package com.ling.simul.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ling.simul.entity.RequestContent;
import com.ling.simul.service.MppCalService;
import com.ling.simul.vo.*;
import lombok.extern.apachecommons.CommonsLog;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;

import static com.ling.simul.utils.CommonUtil.*;


@Service
@CommonsLog
public class MppCalServiceImpl extends BaseService implements MppCalService {

//    @Autowired
//    private EventLossDao eventLossDao;

    @Override
    public ResultData modelEvaluation(JSONObject content, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(content.toString(), RequestContent.class);
        JSONObject resultData = baseCalServiceModelEvaluation(rc);
        Integer code = resultData.getInteger("code");
        String el = rc.getEl();
        String ts = rc.getTs();
        String ys = rc.getYs();
        String n = rc.getN();
        String r = rc.getR();

        if (code == 200) {
            Map<String, Integer> steed_grade_map = new HashMap<>();
            List<ModelEvaluationObject> mes = new ArrayList<>();

            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            JSONArray resultDatas = new JSONArray();

            for (JSONObject result : resultList) {
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                ModelEvaluationObject me = new ModelEvaluationObject();
                try {
                    String grade = null;//牌号
                    JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                    Kv gaCglpdoKv = response.getGA().getCglPdo().getKvs().getKv();
                    //钢种牌号
                    List<String> shopSignCodeList = gaCglpdoKv.getShop_sign_code();
                    if (null != shopSignCodeList && shopSignCodeList.size() > 0) {
                        grade = shopSignCodeList.get(0);
                        if (steed_grade_map.get(grade) != null) {
                            int i = steed_grade_map.get(grade) + 1;
                            steed_grade_map.put(grade, i);
                        } else {
                            steed_grade_map.put(grade, 1);
                        }
                        me.setSteed_grade(grade);
                    } else {
                        continue;
                    }
                    //出口厚度
                    List<Double> thicknessOut = gaCglpdoKv.getThickness_out();
                    if (null != thicknessOut && thicknessOut.size() > 0) {
                        me.setThickness_out(BigDecimal.valueOf(thicknessOut.get(0)));
                    }
                    //获取真实值、预测值
                    Kv gaPredictKv = response.getGA().getPredict().getKvs().getKv();
//                    Kv gaMppKv = response.getGA().getMpp().getKvs().getKv();
                    Kv pltcmMppKv = response.getPLTCM().getMpp().getKvs().getKv();
                    List<Double> predictPointYsList = gaPredictKv.getPredict_point_ys();
                    if (null != predictPointYsList && predictPointYsList.size() > 0) {
                        Double predictPointYs = predictPointYsList.get(0);
                        me.setPredict_ys(BigDecimal.valueOf(predictPointYs));
                    } else {
                    }


                    List<Double> predictPointTsList = gaPredictKv.getPredict_point_ts();
                    if (null != predictPointTsList && predictPointTsList.size() > 0) {
                        Double predictPointTs = predictPointTsList.get(0);
                        me.setPredict_ts(BigDecimal.valueOf(predictPointTs));
                    } else {
                    }


                    List<Double> predictPointElList = gaPredictKv.getPredict_point_el();


                    if (null != predictPointElList && predictPointElList.size() > 0) {
                        Double predictPointEl = predictPointElList.get(0);
                        me.setPredict_el(BigDecimal.valueOf(predictPointEl));
                    } else {
                    }


                    List<Double> predictPointRList = gaPredictKv.getPredict_point_r();
                    if (null != predictPointRList && predictPointRList.size() > 0) {
                        Double predictPointR = predictPointRList.get(0);
                        me.setPredict_r(BigDecimal.valueOf(predictPointR));
                    } else {
                    }


                    List<Double> predictPointNList = gaPredictKv.getPredict_point_n();
                    if (null != predictPointNList && predictPointNList.size() > 0) {
                        Double predictPointN = predictPointNList.get(0);
                        me.setPredict_n(BigDecimal.valueOf(predictPointN));
                    } else {
                    }

                    List<Double> realYs1List = pltcmMppKv.getReal_ys1();
                    List<Double> realTs1List = pltcmMppKv.getReal_ts1();
                    List<Double> realEl1List = pltcmMppKv.getReal_el1();
                    List<Double> realR1List = pltcmMppKv.getReal_r1();
                    List<Double> realN1List = pltcmMppKv.getReal_n1();
                    if (null != realYs1List && realYs1List.size() > 0) {
                        Double realYs1 = realYs1List.get(0);
                        me.setReal_ys(BigDecimal.valueOf(realYs1));
                    } else {
                    }
                    if (null != realTs1List && realTs1List.size() > 0) {
                        Double realTs1 = realTs1List.get(0);
                        me.setReal_ts(BigDecimal.valueOf(realTs1));
                    } else {
                    }
                    if (null != realEl1List && realEl1List.size() > 0) {
                        Double realEl1 = realEl1List.get(0);
                        me.setReal_el(BigDecimal.valueOf(realEl1));
                    } else {
                    }
                    if (null != realR1List && realR1List.size() > 0) {
                        Double realR1 = realR1List.get(0);
                        me.setReal_r(BigDecimal.valueOf(realR1));
                    } else {
                    }
                    if (null != realN1List && realN1List.size() > 0) {
                        Double realN1 = realN1List.get(0);
                        me.setReal_n(BigDecimal.valueOf(realN1));
                    } else {
                    }

                    mes.add(me);


                } catch (JsonMappingException e) {
                    throw new RuntimeException(e);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            }

            steed_grade_map.entrySet().stream().sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).forEach(o -> {

                //屈服误差±（数值范围）
                double ysErr = 10;
                //抗拉误差±（数值范围）
                double tsErr = 10;
                //延伸误差%（百分比）
                double elErr = 3;
                double nErr = 10;
                double rErr = 10;
                if(StringUtils.isNotBlank(ys)){
                    ysErr = Double.valueOf(ys);
                }
                if(StringUtils.isNotBlank(ts)){
                    tsErr = Double.valueOf(ts);
                }
                if(StringUtils.isNotBlank(el)){
                    elErr = Double.valueOf(el);
                }
                if(StringUtils.isNotBlank(n)){
                    nErr = Double.valueOf(n);
                }
                if(StringUtils.isNotBlank(r)){
                    rErr = Double.valueOf(r);
                }
                String key = o.getKey();
                JSONObject json = new JSONObject();

                //检测量
                int detectNum = 0;//检测量
                int ysDetect = 0;
                int tsDetect = 0;
                int elDetect = 0;
                int nDetect = 0;
                int rDetect = 0;
                //绝对误差
                BigDecimal ysError = new BigDecimal("0");
                BigDecimal tsError = new BigDecimal("0");
                BigDecimal elError = new BigDecimal("0");
                BigDecimal nError = new BigDecimal("0");
                BigDecimal rError = new BigDecimal("0");
                //准确率
                int ysAccuracy = 0;
                int tsAccuracy = 0;
                int elAccuracy = 0;
                int nAccuracy = 0;
                int rAccuracy = 0;

                //标准差计算：
                BigDecimal ysSigma = new BigDecimal("0");
                List<BigDecimal> ysSigmaList = new ArrayList<>();
                BigDecimal tsSigma = new BigDecimal("0");
                List<BigDecimal> tsSigmaList = new ArrayList<>();
                BigDecimal elSigma = new BigDecimal("0");
                List<BigDecimal> elSigmaList = new ArrayList<>();
                BigDecimal nSigma = new BigDecimal("0");
                List<BigDecimal> nSigmaList = new ArrayList<>();
                BigDecimal rSigma = new BigDecimal("0");
                List<BigDecimal> rSigmaList = new ArrayList<>();

                for (ModelEvaluationObject meo : mes) {
                    if (key.equals(meo.getSteed_grade())) {

                        if (meo.getReal_ys() != null && BigDecimal.ZERO.compareTo(meo.getReal_ys()) == -1 && meo.getPredict_ys() != null) {
                            ysDetect++;
                            detectNum++;

                            ysError = ysError.add(meo.getReal_ys().subtract(meo.getPredict_ys()).abs());
                            if (compareTo(meo.getPredict_ys(), meo.getReal_ys().add(BigDecimal.valueOf(ysErr)), meo.getReal_ys().subtract(BigDecimal.valueOf(ysErr)))) {
                                ysAccuracy++;
                            }

                        }
                        if (meo.getReal_ts() != null && BigDecimal.ZERO.compareTo(meo.getReal_ts()) == -1 && meo.getPredict_ts() != null) {
                            tsDetect++;

                            tsError = tsError.add(meo.getReal_ts().subtract(meo.getPredict_ts()).abs());
                            if (compareTo(meo.getPredict_ts(), meo.getReal_ts().add(BigDecimal.valueOf(tsErr)), meo.getReal_ts().subtract(BigDecimal.valueOf(tsErr)))) {
                                tsAccuracy++;
                            }
                        }
                        if (meo.getReal_el() != null && BigDecimal.ZERO.compareTo(meo.getReal_el()) == -1 && meo.getPredict_el() != null) {
                            elDetect++;

                            elError = elError.add(meo.getReal_el().subtract(meo.getPredict_el()).abs());

                            if (compareTo(meo.getPredict_el(), meo.getReal_el().add(BigDecimal.valueOf(elErr)), meo.getReal_el().subtract(BigDecimal.valueOf(elErr)))) {
                                elAccuracy++;
                            }
                        }
                        if (meo.getReal_n() != null && BigDecimal.ZERO.compareTo(meo.getReal_n()) == -1 && meo.getPredict_n() != null) {
                            nDetect++;

                            nError = nError.add(meo.getReal_n().subtract(meo.getPredict_n()).abs());
                            if (compareTo(meo.getPredict_n(), meo.getReal_n().add(BigDecimal.valueOf(nErr)), meo.getReal_n().subtract(BigDecimal.valueOf(nErr)))) {
                                nAccuracy++;
                            }
                        }
                        if (meo.getReal_r() != null && BigDecimal.ZERO.compareTo(meo.getReal_r()) == -1 && meo.getPredict_r() != null) {
                            rDetect++;

                            rError = rError.add(meo.getReal_r().subtract(meo.getPredict_r()).abs());
                            if (compareTo(meo.getPredict_r(), meo.getReal_r().add(BigDecimal.valueOf(rErr)), meo.getReal_r().subtract(BigDecimal.valueOf(rErr)))) {
                                rAccuracy++;
                            }
                        }

                        ysSigmaList.add(meo.getPredict_ys());
                        tsSigmaList.add(meo.getPredict_ts());
                        elSigmaList.add(meo.getPredict_el());
                        nSigmaList.add(meo.getPredict_n());
                        rSigmaList.add(meo.getPredict_r());


                    }
                }

                if (detectNum != 0) {
                    ysSigma = getNumber(StandardDiviation(ysSigmaList));
                    tsSigma = getNumber(StandardDiviation(tsSigmaList));
                    elSigma = getNumber(StandardDiviation(elSigmaList));
                    nSigma = getNumber(StandardDiviation(nSigmaList));
                    rSigma = getNumber(StandardDiviation(rSigmaList));

                    json.put("detectNum", detectNum);

                    json.put("ysDetect", ysDetect);
                    json.put("tsDetect", tsDetect);
                    json.put("elDetect", elDetect);
                    json.put("nDetect", nDetect);
                    json.put("rDetect", rDetect);

                    json.put("ysSigma", ysSigma);
                    json.put("tsSigma", tsSigma);
                    json.put("elSigma", elSigma);
                    json.put("nSigma", nSigma);
                    json.put("rSigma", rSigma);

                    json.put("ysAccuracyNum", ysAccuracy);
                    json.put("tsAccuracyNum", tsAccuracy);
                    json.put("elAccuraNumcy", elAccuracy);
                    json.put("nAccuracyNum", nAccuracy);
                    json.put("rAccuracyNum", rAccuracy);

                    if (ysDetect != 0) {
                        json.put("ysError", ysError.divide(getNumber(ysDetect), 2, RoundingMode.HALF_UP));
                        json.put("ysAccuracy", BigDecimal.valueOf(ysAccuracy).divide(BigDecimal.valueOf(ysDetect), 2, RoundingMode.HALF_UP));

                    } else {
                        json.put("ysError", null);
                        json.put("ysAccuracy", null);
                    }
                    if (tsDetect != 0) {
                        json.put("tsError", tsError.divide(getNumber(tsDetect), 2, RoundingMode.HALF_UP));
                        json.put("tsAccuracy", BigDecimal.valueOf(tsAccuracy).divide(BigDecimal.valueOf(tsDetect), 2, RoundingMode.HALF_UP));
                    } else {
                        json.put("tsError", null);
                        json.put("tsAccuracy", null);
                    }

                    if (elDetect != 0) {
                        json.put("elError", elError.divide(getNumber(elDetect), 2, RoundingMode.HALF_UP));
                        json.put("elAccuracy", BigDecimal.valueOf(elAccuracy).divide(BigDecimal.valueOf(elDetect), 2, RoundingMode.HALF_UP));
                    } else {
                        json.put("elError", null);
                        json.put("elAccuracy", null);
                    }
                    if (nDetect != 0) {
                        json.put("nError", nError.divide(getNumber(nDetect), 2, RoundingMode.HALF_UP));
                        json.put("nAccuracy", BigDecimal.valueOf(nAccuracy).divide(BigDecimal.valueOf(nDetect), 2, RoundingMode.HALF_UP));
                    } else {
                        json.put("nError", null);
                        json.put("nAccuracy", null);
                    }

                    if (rDetect != 0) {
                        json.put("rError", rError.divide(getNumber(rDetect), 2, RoundingMode.HALF_UP));
                        json.put("rAccuracy", BigDecimal.valueOf(rAccuracy).divide(BigDecimal.valueOf(rDetect), 2, RoundingMode.HALF_UP));
                    } else {
                        json.put("rError", null);
                        json.put("rAccuracy", null);
                    }
                    json.put("grade", key);
                    resultDatas.add(json);
                }

            });

            JSONObject data = new JSONObject();
            data.put("tableData", resultDatas);
            return ResultData.ResultDataSuccess(data);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData predictTrend(JSONObject content, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(content.toString(), RequestContent.class);
        // 获取数据中心数据
        JSONObject resultData = baseCalServicePredictTrend(rc);
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");

        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);

            //是否累加   0 不累加
            int type = 0;
            //每组卷数
            int num = 10;
            //屈服误差±（数值范围）
            double ysError = 10;
            //抗拉误差±（数值范围）
            double tsError = 10;
            //延伸误差%（百分比）
            double elError = 3;
            double nError = 10;
            double rError = 10;

            if (StringUtils.isNotBlank(rc.getType())) {
                type = Integer.parseInt(rc.getType());
            }

            JSONObject ys = new JSONObject();
            JSONObject ts = new JSONObject();
            JSONObject el = new JSONObject();
            JSONObject n = new JSONObject();
            JSONObject r = new JSONObject();

            //在误差之内的数量（最后要除以总数）
            int accr_ys = 0;
            int accr_ts = 0;
            int accr_el = 0;
            int accr_n = 0;
            int accr_r = 0;
            //准确率和误差
            JSONArray error1 = new JSONArray();
            JSONArray accr1 = new JSONArray();
            JSONArray error2 = new JSONArray();
            JSONArray accr2 = new JSONArray();
            JSONArray error3 = new JSONArray();
            JSONArray accr3 = new JSONArray();
            JSONArray error4 = new JSONArray();
            JSONArray accr4 = new JSONArray();
            JSONArray error5 = new JSONArray();
            JSONArray accr5 = new JSONArray();

            ys.put("error", error1);
            ys.put("accr", accr1);
            ts.put("error", error2);
            ts.put("accr", accr2);
            el.put("error", error3);
            el.put("accr", accr3);
            n.put("error", error4);
            n.put("accr", accr4);
            r.put("error", error5);
            r.put("accr", accr5);

            BigDecimal error_ys = new BigDecimal("0.0");
            BigDecimal error_ts = new BigDecimal("0.0");
            BigDecimal error_el = new BigDecimal("0.0");
            BigDecimal error_n = new BigDecimal("0.0");
            BigDecimal error_r = new BigDecimal("0.0");

            int ys_num = 0;
            int ts_num = 0;
            int el_num = 0;
            int n_num = 0;
            int r_num = 0;

            JSONArray array = new JSONArray();
            JSONArray arrayGroup = new JSONArray();

//            JSONObject resultDatas = new JSONObject();
//            List<Double> errorYsList = new ArrayList<>();
//            JSONObject errorYsObj = new JSONObject();
//            int ysZhunCount = 0;
//            Double zhunqueYs = null; //准确率
//            for (JSONObject result : resultList) {
            for (int i = 0; i < resultList.size(); i++) {
                JSONObject json = new JSONObject();
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = resultList.get(i).toJSONString();
                try {
                    JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
//                    Kv gaMppKv = response.getGA().getMpp().getKvs().getKv();
                    Kv gaPredictKv = response.getGA().getPredict().getKvs().getKv();
                    Kv pltcmMppKv = response.getPLTCM().getMpp().getKvs().getKv();

                    List<Double> realYs1List = pltcmMppKv.getReal_ys1();
                    List<Double> realTs1List = pltcmMppKv.getReal_ts1();
                    List<Double> realEl1List = pltcmMppKv.getReal_el1();
                    List<Double> realR1List = pltcmMppKv.getReal_r1();
                    List<Double> realN1List = pltcmMppKv.getReal_n1();

                    List<Double> predictPointYsList = gaPredictKv.getPredict_point_ys();
                    List<Double> predictPointTsList = gaPredictKv.getPredict_point_ts();
                    List<Double> predictPointElList = gaPredictKv.getPredict_point_el();
                    List<Double> predictPointRList = gaPredictKv.getPredict_point_r();
                    List<Double> predictPointNList = gaPredictKv.getPredict_point_n();

                    Double realYs = null; //实际
                    Double predictYs = null; //预测
                    Double realTs = null;
                    Double predictTs = null;
                    Double realEl = null;
                    Double predictEl = null;
                    Double realR = null;
                    Double predictR = null;
                    Double realN = null;
                    Double predictN = null;

//                    json.put("coil_no_out",coil_no_out);
//                    json.put("shop_sign",shop_sign);
//                    json.put("create_time",create_time);


                    //屈服
                    if (null != realYs1List && realYs1List.size() > 0) {
                        realYs = realYs1List.get(0); //实际
                        json.put("real_ys", realYs);
                    }
                    if (null != predictPointYsList && predictPointYsList.size() > 0) {
                        predictYs = predictPointYsList.get(0); //预测
                        json.put("predict_ys", predictYs);
                    }
                    //ts
                    if (null != realTs1List && realTs1List.size() > 0) {
                        realTs = realTs1List.get(0); //实际
                        json.put("real_ts", realTs);
                    }
                    if (null != predictPointTsList && predictPointTsList.size() > 0) {
                        predictTs = predictPointTsList.get(0); //预测
                        json.put("predict_ts", predictTs);
                    }
                    //el
                    if (null != realEl1List && realEl1List.size() > 0) {
                        realEl = realEl1List.get(0); //实际
                        json.put("real_el", realEl);
                    }
                    if (null != predictPointElList && predictPointElList.size() > 0) {
                        predictEl = predictPointElList.get(0); //预测
                        json.put("predict_el", predictEl);
                    }
                    //r
                    if (null != realR1List && realR1List.size() > 0) {
                        realR = realR1List.get(0); //实际
                        json.put("real_r", realR);
                    }
                    if (null != predictPointRList && predictPointRList.size() > 0) {
                        predictR = predictPointRList.get(0); //预测
                        json.put("predict_r", predictR);
                    }
                    //n
                    if (null != realN1List && realN1List.size() > 0) {
                        realN = realN1List.get(0); //实际
                        json.put("real_n", realN);
                    }
                    if (null != predictPointNList && predictPointNList.size() > 0) {
                        predictN = predictPointNList.get(0); //预测
                        json.put("predict_n", predictN);
                    }

                    //只有屈服，抗拉，延申等都合格才符合标准。 用err判定这些属性是否都合格。
                    int err = 0;

                    if (realYs != null && predictYs != null && 0 != realYs) {
                        error_ys = error_ys.add(BigDecimal.valueOf(Math.abs(realYs - predictYs)));
                        ys_num++;
//                    if(calculateRange(predict_ys,real_ys,BigDecimal.valueOf(ysError))){
//                        accr_ys++;
//                    }
//                        if(compareTo(predictYs,realYs+ysError, realYs-ysError){
                        if (predictYs < (realYs + ysError) && predictYs > (realYs - ysError)) {
                            accr_ys++;
                        } else {
                            err++;
                        }
                        //1. 由于这100卷要保证都有预测值和实际值,所以要统计ys_num，如果当前ys_num% num == number ,要统计这100卷的误差和准确率
                        if (ys_num % num == 0) {
                            //如果不累加，每100组统计一次
                            if (type == 0) {
                                BigDecimal e = error_ys.divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ys).divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error1.add(e);
                                accr1.add(a);
                                error_ys = BigDecimal.ZERO;
                                accr_ys = 0;
                            } else {
                                //如果累加，每100组统计一次，但是需要加上前面几组的数值，除以累加后的卷数
                                BigDecimal e = error_ys.divide(BigDecimal.valueOf(ys_num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ys).divide(BigDecimal.valueOf(ys_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error1.add(e);
                                accr1.add(a);
                            }

                        } else if (i == resultList.size() - 1) {
                            //2. 如果当前ys_num % num < number ,要判断是否已经遍历结束
                            if (type == 0) {
                                int ab = ys_num % num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_ys.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ys).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error1.add(e);
                                accr1.add(a);
                            } else {
                                int ab = ys_num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_ys.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ys).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error1.add(e);
                                accr1.add(a);
                            }
                        }
                    } else {
                        if (i == resultList.size() - 1) {
                            if (type == 0) {
                                int ab = ys_num % num;
                                if (ab == 0) {
                                    continue;
                                }

                                BigDecimal e = error_ys.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ys).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error1.add(e);
                                accr1.add(a);
                            } else {
                                int ab = ys_num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_ys.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ys).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error1.add(e);
                                accr1.add(a);
                            }
                        }
                    }
                    if (realTs != null && predictTs != null && realTs > 0) {
//                        error_ts = error_ts.add(realTs.subtract(predictTs).abs());
                        error_ts = error_ts.add(BigDecimal.valueOf(Math.abs(realTs - predictTs)));
                        ts_num++;
//                    if(calculateRange(predict_ts,real_ts,BigDecimal.valueOf(tsError))){
//                        accr_ts++;
//                    }
//                        if(compareTo(predictTs,realTs.add(BigDecimal.valueOf(tsError)), realTs.subtract(BigDecimal.valueOf(tsError)))){
                        if (predictTs > realTs - tsError && predictTs < realTs + tsError) {
                            accr_ts++;
                        } else {
                            err++;
                        }
                        //1. 由于这100卷要保证都有预测值和实际值,所以要统计ts_num，如果当前ys_num% num == 0 ,要统计这100卷的误差和准确率
                        if (ts_num % num == 0) {
                            if (type == 0) {
                                BigDecimal e = error_ts.divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ts).divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error2.add(e);
                                accr2.add(a);
                                error_ts = BigDecimal.ZERO;
                                accr_ts = 0;
                            } else {
                                //如果累加，每100组统计一次，但是需要加上前面几组的数值，除以累加后的卷数
                                BigDecimal e = error_ts.divide(BigDecimal.valueOf(ts_num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ts).divide(BigDecimal.valueOf(ts_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error2.add(e);
                                accr2.add(a);
                            }

                        } else if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            if (type == 0) {
                                //统计剩余的不足100卷的数据
                                int ab = ts_num % num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_ts.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ts).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error2.add(e);
                                accr2.add(a);
                            } else {
                                int ab = ts_num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_ts.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ts).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error2.add(e);
                                accr2.add(a);
                            }

                        }
                    } else {
                        if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            if (type == 0) {
                                //统计剩余的不足100卷的数据
                                int ab = ts_num % num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_ts.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ts).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error2.add(e);
                                accr2.add(a);
                            } else {
                                int ab = ts_num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_ts.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_ts).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error2.add(e);
                                accr2.add(a);
                            }

                        }
                    }
                    if (realEl != null && predictEl != null && realEl > 0) {
//                        error_el = error_el.add(real_el.subtract(predict_el).abs());
                        error_el = error_el.add(BigDecimal.valueOf(Math.abs(realEl - predictEl)));
                        el_num++;
//                    if(calculateRange(predict_el,real_el,BigDecimal.valueOf(elError))){
//                        accr_el++;
//                    }

//                        if(compareTo(predict_el,real_el.add(BigDecimal.valueOf(elError)), real_el.subtract(BigDecimal.valueOf(elError)))){
                        if (predictEl > realEl - elError && predictEl < realEl + elError) {
                            accr_el++;
                        } else {
                            err++;
                        }

                        //1. 由于这100卷要保证都有预测值和实际值,所以要统计el_num，如果当前el_num% num == number ,要统计这100卷的误差和准确率
                        if (el_num % num == 0) {
                            if (type == 0) {
                                BigDecimal e = error_el.divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_el).divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error3.add(e);
                                accr3.add(a);
                                error_el = BigDecimal.ZERO;
                                accr_el = 0;
                            } else {
                                //如果累加，每100组统计一次，但是需要加上前面几组的数值，除以累加后的卷数
                                BigDecimal e = error_el.divide(BigDecimal.valueOf(el_num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_el).divide(BigDecimal.valueOf(el_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error3.add(e);
                                accr3.add(a);
                            }

                        } else if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            if (type == 0) {
                                //统计剩余的不足100卷的数据
                                int ab = el_num % num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_el.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_el).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error3.add(e);
                                accr3.add(a);

                            } else {
                                int ab = el_num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_el.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_el).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error3.add(e);
                                accr3.add(a);
                            }
                        }
                    } else {
                        if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            if (type == 0) {
                                //统计剩余的不足100卷的数据
                                int ab = el_num % num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_el.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_el).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error3.add(e);
                                accr3.add(a);

                            } else {
                                int ab = el_num;
                                if (ab == 0) {
                                    continue;
                                }
                                BigDecimal e = error_el.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_el).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error3.add(e);
                                accr3.add(a);
                            }
                        }
                    }
                    if (realN != null && predictN != null && realN > 0) {
//                        error_n = error_n.add(real_n.subtract(predict_n).abs());
                        error_n = error_n.add(BigDecimal.valueOf(Math.abs(realN - predictN)));
                        n_num++;
//                    if(calculateRange(predict_n,real_n,BigDecimal.valueOf(nError))){
//                        accr_n++;
//                    }
//                        if(compareTo(predict_n,real_n.add(BigDecimal.valueOf(nError)), real_n.subtract(BigDecimal.valueOf(nError)))){
                        if (predictN > realN - nError && predictN < realN + nError) {
                            accr_n++;
                        } else {
                            err++;
                        }
                        //1. 由于这100卷要保证都有预测值和实际值,所以要统计el_num，如果当前el_num% num == 0 ,要统计这100卷的误差和准确率
                        if (n_num % num == 0) {
                            if (type == 0) {
                                BigDecimal e = error_n.divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_n).divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error4.add(e);
                                accr4.add(a);
                                error_n = BigDecimal.ZERO;
                                accr_n = 0;
                            } else {
                                //如果累加，每100组统计一次，但是需要加上前面几组的数值，除以累加后的卷数
                                BigDecimal e = error_n.divide(BigDecimal.valueOf(n_num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_n).divide(BigDecimal.valueOf(n_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error4.add(e);
                                accr4.add(a);
                            }

                        } else if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            int ab = n_num % num;
                            if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(ab)) == 0) {

                            } else {
                                //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                                if (type == 0) {
                                    //统计剩余的不足100卷的数据
                                    BigDecimal e = error_n.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_n).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error4.add(e);
                                    accr4.add(a);

                                } else {
                                    BigDecimal e = error_n.divide(BigDecimal.valueOf(n_num), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_n).divide(BigDecimal.valueOf(n_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error4.add(e);
                                    accr4.add(a);
                                }
                            }
                        }
                    } else {
                        if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            int ab = n_num % num;
                            if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(ab)) == 0) {

                            } else {
                                //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                                if (type == 0) {
                                    //统计剩余的不足100卷的数据
                                    BigDecimal e = error_n.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_n).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error4.add(e);
                                    accr4.add(a);

                                } else {
                                    BigDecimal e = error_n.divide(BigDecimal.valueOf(n_num), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_n).divide(BigDecimal.valueOf(n_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error4.add(e);
                                    accr4.add(a);
                                }
                            }
                        }
                    }
                    if (realR != null && predictR != null && realR > 0) {
//                        error_r = error_r.add(real_r.subtract(predict_r).abs());
                        error_r = error_r.add(BigDecimal.valueOf(Math.abs(realR - predictR)));
                        r_num++;
//                    if(calculateRange(predict_r,real_r,BigDecimal.valueOf(rError))){
//                        accr_r++;
//                    }
//                        if(compareTo(predict_r,real_r.add(BigDecimal.valueOf(rError)), real_r.subtract(BigDecimal.valueOf(rError)))){
                        if (predictR > realR - rError && predictR < realR + rError) {
                            accr_r++;
                        } else {
                            err++;
                        }

                        //1. 由于这100卷要保证都有预测值和实际值,所以要统计el_num，如果当前el_num% num == 0 ,要统计这100卷的误差和准确率
                        if (r_num % num == 0) {
                            if (type == 0) {
                                BigDecimal e = error_r.divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_r).divide(BigDecimal.valueOf(num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error5.add(e);
                                accr5.add(a);
                                error_r = BigDecimal.ZERO;
                                accr_r = 0;
                            } else {
                                //如果累加，每100组统计一次，但是需要加上前面几组的数值，除以累加后的卷数
                                BigDecimal e = error_r.divide(BigDecimal.valueOf(r_num), 4, RoundingMode.HALF_UP);
                                BigDecimal a = BigDecimal.valueOf(accr_r).divide(BigDecimal.valueOf(r_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                error5.add(e);
                                accr5.add(a);
                            }

                        } else if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            int ab = r_num % num;
                            if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(ab)) == 0) {

                            } else {

                                //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                                if (type == 0) {
                                    //统计剩余的不足100卷的数据
                                    BigDecimal e = error_r.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_r).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error5.add(e);
                                    accr5.add(a);

                                } else {
                                    BigDecimal e = error_r.divide(BigDecimal.valueOf(r_num), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_r).divide(BigDecimal.valueOf(r_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error5.add(e);
                                    accr5.add(a);
                                }
                            }
                        }
                    } else {
                        if (i == resultList.size() - 1) {
                            //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                            int ab = r_num % num;
                            if (BigDecimal.ZERO.compareTo(BigDecimal.valueOf(ab)) == 0) {

                            } else {

                                //2. 如果当前ts_num % num < number ,要判断是否已经遍历结束
                                if (type == 0) {
                                    //统计剩余的不足100卷的数据
                                    BigDecimal e = error_r.divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_r).divide(BigDecimal.valueOf(ab), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error5.add(e);
                                    accr5.add(a);

                                } else {
                                    BigDecimal e = error_r.divide(BigDecimal.valueOf(r_num), 4, RoundingMode.HALF_UP);
                                    BigDecimal a = BigDecimal.valueOf(accr_r).divide(BigDecimal.valueOf(r_num), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                                    error5.add(e);
                                    accr5.add(a);
                                }
                            }
                        }
                    }
                    json.put("state", err == 0 ? null : "red");
                    if (i == 0) {
                        array.add(json);
                        continue;
                    }

                    //每一组
                    if (i % num == 0) {
                        arrayGroup.add(array);
                        array = new JSONArray();
                        array.add(json);
                    } else if (i == resultList.size() - 1) {
                        arrayGroup.add(array);
                    } else {
                        array.add(json);
                    }


                } catch (JsonMappingException e) {
                    throw new RuntimeException(e);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            }
//
            JSONObject data = new JSONObject();
            data.put("ys", ys);
            data.put("ts", ts);
            data.put("el", el);
            data.put("n", n);
            data.put("r", r);
            data.put("info", arrayGroup);
            return ResultData.ResultDataSuccess(data);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData getShopSignCode(JSONObject content, String url) {
        // 获取数据中心数据
        JSONObject resultData = baseCalServiceGetShopSignCode();
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");
        //保存全部的钢卷号
        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            JSONArray resultDatas = new JSONArray();
            ArrayList<String> strList = new ArrayList<>();
            ArrayList<String> results = new ArrayList<>();
            for (JSONObject result : resultList) {
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                try {
                    JResponse2 response2 = objectMapper.readValue(jsonString, JResponse2.class);
                    Kv2 kv = response2.getGA().getCglPdo().getKvs().getKv();
                    String shopSignCode = kv.getShop_sign_code();
                    if (null != shopSignCode) {
                        strList.add(shopSignCode);
//                        resultDatas.add(shopSignCode);
                    }
                } catch (JsonMappingException e) {
                    throw new RuntimeException(e);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }

            }
            for (String s : strList) {
                if (results.contains(s)) {
                    continue;
                } else {
                    results.add(s);
                }
            }
            for (String st : results) {
                resultDatas.add(st);
            }
            JSONObject data = new JSONObject();
            data.put("tableData", resultDatas);
            // 计算总条数 添加
            Integer total = 0;
            data.put("total", total);
            return ResultData.ResultDataSuccess(data, total);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData historyTable(JSONObject content, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(content.toString(), RequestContent.class);
        //异步获取total
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            try {
                return getCountHistoryTable(rc);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        });
        // 获取数据中心数据
        JSONObject resultData = baseCalServiceHistoryTable(rc);
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");
        //保存全部的钢卷号
        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            JSONArray resultDatas = new JSONArray();

            for (JSONObject result : resultList) {
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                JSONObject json = new JSONObject();

                JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                Kv gaCglpdiKv = response.getGA().getCglPdi().getKvs().getKv();
                Kv gaCglpdoKv = response.getGA().getCglPdo().getKvs().getKv();
                Kv gaPredictKv = response.getGA().getPredict().getKvs().getKv();
                Kv hsmHsmpdoKv = response.getHSM().getHSM_PDO().getKvs().getKv();
                Kv pltcmMppKv = response.getPLTCM().getMpp().getKvs().getKv();

                List<Double> sizeProductLenList = hsmHsmpdoKv.getSize_product_len();
                if (null != sizeProductLenList && sizeProductLenList.size() > 0) {
                    Double sizeProductLen = sizeProductLenList.get(0);
                    json.put("size_product_len", sizeProductLen);//长度
                } else {
                    json.put("size_product_len", null);//长度
                }

                List<String> hotCoilNoList = gaCglpdiKv.getHot_coil_no();
                if (null != hotCoilNoList && hotCoilNoList.size() > 0) {
                    String hotCoilNo = hotCoilNoList.get(0);
                    json.put("hot_coil_no", hotCoilNo); //热轧卷号
                } else {
                    json.put("hot_coil_no", null); //热轧卷号
                }

                List<String> coilNoOut = gaCglpdoKv.getCoil_no_out();
                if (null != coilNoOut && coilNoOut.size() > 0) {
                    json.put("coil_no_out", coilNoOut.get(0)); //卷号
                } else {
                    json.put("coil_no_out", null); //卷号
                }

                List<Double> thicknessOut = gaCglpdoKv.getThickness_out();
                if (null != thicknessOut && thicknessOut.size() > 0) {
                    json.put("thickness_out", thicknessOut.get(0)); //厚度
                } else {
                    json.put("thickness_out", null); //厚度
                }

                List<String> shopSignCode = gaCglpdoKv.getShop_sign_code();
                if (null != shopSignCode && shopSignCode.size() > 0) {
                    json.put("shop_sign_code", shopSignCode.get(0)); //钢种
                } else {
                    json.put("shop_sign_code", null); //钢种
                }

                List<String> productTime = gaCglpdoKv.getProduct_time();
                if (null != productTime && productTime.size() > 0) {
                    String s = productTime.get(0);
                    json.put("product_time", s);
                } else {
                    json.put("product_time", null); //生产结束时间
                }
                List<Double> widthOut = gaCglpdoKv.getWidth_out();
                if (null != widthOut && widthOut.size() > 0) {
                    json.put("width_out", widthOut.get(0)); //宽度
                } else {
                    json.put("width_out", null); //宽度
                }

                List<Double> yieldMaxList = gaPredictKv.getYield_max();
                List<Double> yieldMinList = gaPredictKv.getYield_min();
                List<Double> predictPointYsList = gaPredictKv.getPredict_point_ys();
                List<Double> passRateYsList = gaPredictKv.getPass_rate_ys();
                Double yieldMax = null;
                if (null != yieldMaxList && yieldMaxList.size() > 0) {
                    yieldMax = yieldMaxList.get(0);
                    json.put("yield_max", yieldMax);
                } else {
                    json.put("yield_max", null);
                }
                Double yieldMin = null;
                if (null != yieldMinList && yieldMinList.size() > 0) {
                    yieldMin = yieldMinList.get(0);
                    json.put("yield_min", yieldMin);
                } else {
                    json.put("yield_min", null);
                }
                Double predictPointYs = null;
                if (null != predictPointYsList && predictPointYsList.size() > 0) {
                    predictPointYs = predictPointYsList.get(0);
                    json.put("predict_ys", predictPointYs);
                } else {
                    json.put("predict_ys", null);
                }
                Double passRateYs = null;
                if (null != passRateYsList && passRateYsList.size() > 0) {
                    passRateYs = passRateYsList.get(0);
                    json.put("pass_rate_ys", passRateYs);
                } else {
                    json.put("pass_rate_ys", null);
                }
                if (null != predictPointYs && predictPointYs != 0) {
                    if (null != yieldMax && null != yieldMin) {
                        if (predictPointYs >= yieldMin && predictPointYs <= yieldMax) {
                            //合格
                            json.put("yi_accurate",true);
                        } else {
                            json.put("yi_accurate",false);
                        }
                    } else {
                        json.put("yi_accurate",true);
                    }
                } else {
                    json.put("yi_accurate",true);
                }

                List<Double> tensionMaxList = gaPredictKv.getTension_max();
                List<Double> tensionMinList = gaPredictKv.getTension_min();
                List<Double> predictPointTsList = gaPredictKv.getPredict_point_ts();
                List<Double> passRateTsList = gaPredictKv.getPass_rate_ts();
                Double tensionMax = null;
                if (null != tensionMaxList && tensionMaxList.size() > 0) {
                    tensionMax = tensionMaxList.get(0);
                    json.put("tension_max", tensionMax);
                } else {
                    json.put("tension_max", null);
                }
                Double tensionMin = null;
                if (null != tensionMinList && tensionMinList.size() > 0) {
                    tensionMin = tensionMinList.get(0);
                    json.put("tension_min", tensionMin);
                } else {
                    json.put("tension_min", null);
                }
                Double predictPointTs = null;
                if (null != predictPointTsList && predictPointTsList.size() > 0) {
                    predictPointTs = predictPointTsList.get(0);
                    json.put("predict_ts", predictPointTs);
                } else {
                    json.put("predict_ts", null);
                }
                if (null != passRateTsList && passRateTsList.size() > 0) {
                    Double passRateTs = passRateTsList.get(0);
                    json.put("pass_rate_ts", passRateTs);
                } else {
                    json.put("pass_rate_ts", null);
                }
                if (null != predictPointTs && predictPointTs != 0) {
                    if (null != tensionMax && null != tensionMin) {
                        if (predictPointTs >= tensionMin && predictPointTs <= tensionMax) {
                            //合格
                            json.put("ts_accurate",true);
                        } else {
                            json.put("ts_accurate",false);
                        }
                    } else {
                        json.put("ts_accurate",true);
                    }
                } else {
                    json.put("ts_accurate",true);
                }


                List<Double> elMinList = gaPredictKv.getEl_min();
                List<Double> elMaxList = gaPredictKv.getEl_max();
                List<Double> predictPointElList = gaPredictKv.getPredict_point_el();
                List<Double> passRateElList = gaPredictKv.getPass_rate_el();
                Double elMax = null;
                if (null != elMaxList && elMaxList.size() > 0) {
                    elMax = elMaxList.get(0);
                    json.put("el_max", elMax);
                } else {
                    json.put("el_max", null);
                }
                Double elMin = null;
                if (null != elMinList && elMinList.size() > 0) {
                    elMin = elMinList.get(0);
                    json.put("el_min", elMin);
                } else {
                    json.put("el_min", null);
                }
                Double predictPointEl = null;
                if (null != predictPointElList && predictPointElList.size() > 0) {
                    predictPointEl = predictPointElList.get(0);
                    json.put("predict_el", predictPointEl);
                } else {
                    json.put("predict_el", null);
                }
                if (null != passRateElList && passRateElList.size() > 0) {
                    Double passRateEl = passRateElList.get(0);
                    json.put("pass_rate_el", passRateEl);
                } else {
                    json.put("pass_rate_el", null);
                }

                if (null != predictPointEl && predictPointEl != 0) {
                    if (null != elMax && null != elMin) {
                        if (predictPointEl >= elMin && predictPointEl <= elMax) {
                            //合格
                            json.put("el_accurate",true);
                        } else {
                            json.put("el_accurate",false);
                        }
                    } else {
                        json.put("el_accurate",true);
                    }
                } else {
                    json.put("el_accurate",true);
                }

                List<Double> rMinList = gaPredictKv.getR_min();
                List<Double> rMaxList = gaPredictKv.getR_max();
                List<Double> passRateRList = gaPredictKv.getPass_rate_r();
                List<Double> predictPointRList = gaPredictKv.getPredict_point_r();
                if (null != rMaxList && rMaxList.size() > 0) {
                    Double rMax = rMaxList.get(0);
                    json.put("r_max", rMax);
                } else {
                    json.put("r_max", null);
                }
                if (null != rMinList && rMinList.size() > 0) {
                    Double rMin = rMinList.get(0);
                    json.put("r_min", rMin);
                } else {
                    json.put("r_min", null);
                }
                if (null != predictPointRList && predictPointRList.size() > 0) {
                    Double predictPointR = predictPointRList.get(0);
                    json.put("predict_r", predictPointR);
                } else {
                    json.put("predict_r", null);
                }
                if (null != passRateRList && passRateRList.size() > 0) {
                    Double passRateR = passRateRList.get(0);
                    json.put("pass_rate_r", passRateR);
                } else {
                    json.put("pass_rate_r", null);
                }

                List<Double> predictPointNList = gaPredictKv.getPredict_point_n();
                List<Double> nMinList = gaPredictKv.getN_min();
                List<Double> nMaxList = gaPredictKv.getN_max();
                List<Double> passRateNList = gaPredictKv.getPass_rate_n();
                if (null != nMaxList && nMaxList.size() > 0) {
                    Double nMax = nMaxList.get(0);
                    json.put("n_max", nMax);
                } else {
                    json.put("n_max", null);
                }

                if (null != nMinList && nMinList.size() > 0) {
                    Double nMin = nMinList.get(0);
                    json.put("n_min", nMin);
                } else {
                    json.put("n_min", null);
                }

                if (null != predictPointNList && predictPointNList.size() > 0) {
                    Double predictPointN = predictPointNList.get(0);
                    json.put("predict_n", predictPointN);
                } else {
                    json.put("predict_n", null);
                }
                if (null != passRateNList && passRateNList.size() > 0) {
                    Double passRateN = passRateNList.get(0);
                    json.put("pass_rate_n", passRateN);
                } else {
                    json.put("pass_rate_n", null);
                }

                List<Double> realYs1List = pltcmMppKv.getReal_ys1();
                List<Double> realTs1List = pltcmMppKv.getReal_ts1();
                List<Double> realEl1List = pltcmMppKv.getReal_el1();
                List<Double> realR1List = pltcmMppKv.getReal_r1();
                List<Double> realN1List = pltcmMppKv.getReal_n1();
                if (null != realYs1List && realYs1List.size() > 0) {
                    Double realYs1 = realYs1List.get(0);
                    json.put("real_ys1", realYs1);
                } else {
                    json.put("real_ys1", null);
                }
                if (null != realTs1List && realTs1List.size() > 0) {
                    Double realTs1 = realTs1List.get(0);
                    json.put("real_ts1", realTs1);
                } else {
                    json.put("real_ts1", null);
                }
                if (null != realEl1List && realEl1List.size() > 0) {
                    Double realEl1 = realEl1List.get(0);
                    json.put("real_el1", realEl1);
                } else {
                    json.put("real_el1", null);
                }
                if (null != realR1List && realR1List.size() > 0) {
                    Double realR1 = realR1List.get(0);
                    json.put("real_r1", realR1);
                } else {
                    json.put("real_r1", null);
                }
                if (null != realN1List && realN1List.size() > 0) {
                    Double realN1 = realN1List.get(0);
                    json.put("real_n1", realN1);
                } else {
                    json.put("real_n1", null);
                }

                resultDatas.add(json);
            }
            JSONObject data = new JSONObject();
            data.put("tableData", resultDatas);
            Integer total = future.join();
            data.put("total", total);
            return ResultData.ResultDataSuccess(data, total);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData historyeStatic(JSONObject content, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(content.toString(), RequestContent.class);
        // 获取数据中心数据
        JSONObject resultData = baseCalServiceHistoryStatic2(rc);
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");

        List<JSONObject> resultList = null;
        if (code == 200) {
            resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            int m = 0;
            //yield性能合格和不合格的卷数
            int yield_number_true = 0;
            int yield_number_false = 0;
            List<String> ysFalseMatNo = new ArrayList<>();
            //tension性能合格和不合格的卷数
            int tension_number_true = 0;
            int tension_number_false = 0;
            List<String> tsFalseMatNo = new ArrayList<>();
            //el性能合格和不合格的卷数
            int el_number_true = 0;
            int el_number_false = 0;
            List<String> elFalseMatNo = new ArrayList<>();
            //n性能合格和不合格的卷数
            AtomicInteger totalValue = new AtomicInteger(0);
            //饼图
            Map<String, Integer> steed_grade_map = new HashMap<>();


            for (JSONObject result : resultList) {
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                Kv predictKv = response.getGA().getPredict().getKvs().getKv();
                Kv gaPdoKv = response.getGA().getCglPdo().getKvs().getKv();

                Double predictYs = null;
                Double predictTs = null;
                Double predictEl = null;
                Double ysMax = null;
                Double ysMin = null;
                Double tsMax = null;
                Double tsMin = null;
                Double elMax = null;
                Double elMin = null;

                //查卷号
                String coilNo = null;
                List<String> coilNoOut = gaPdoKv.getCoil_no_out();
                if (null != coilNoOut && coilNoOut.size() > 0) {
                    coilNo = coilNoOut.get(0);
                }

                //查牌号
                String shopSignCode = null;
                Kv cglpdoKv = response.getGA().getCglPdo().getKvs().getKv();
                List<String> shopSignCodeList = cglpdoKv.getShop_sign_code();
                if (null != shopSignCodeList && shopSignCodeList.size() > 0) {
                    shopSignCode = shopSignCodeList.get(0);
                }
                if (steed_grade_map.get(shopSignCode) != null) {
                    int i = steed_grade_map.get(shopSignCode) + 1;
                    steed_grade_map.put(shopSignCode, i);
                } else {
                    steed_grade_map.put(shopSignCode, 1);
                }
                //取3个预测值
                List<Double> predictPointYs = predictKv.getPredict_point_ys();
                if (null != predictPointYs && predictPointYs.size() > 0) {
                    predictYs = predictPointYs.get(0);
                }
                List<Double> predictPointTs = predictKv.getPredict_point_ts();
                if (null != predictPointTs && predictPointTs.size() > 0) {
                    predictTs = predictPointTs.get(0);
                }
                List<Double> predictPointEl = predictKv.getPredict_point_el();
                if (null != predictPointEl && predictPointEl.size() > 0) {
                    predictEl = predictPointEl.get(0);
                }
                //取5个上下限
                List<Double> yieldMax = predictKv.getYield_max();
                if (null != yieldMax && yieldMax.size() > 0) {
                    ysMax = yieldMax.get(0);
                }
                List<Double> yieldMin = predictKv.getYield_min();
                if (null != yieldMin && yieldMin.size() > 0) {
                    ysMin = yieldMin.get(0);
                }
                List<Double> tensionMax = predictKv.getTension_max();
                if (null != tensionMax && tensionMax.size() > 0) {
                    tsMax = tensionMax.get(0);
                }
                List<Double> tensionMin = predictKv.getTension_min();
                if (null != tensionMin && tensionMin.size() > 0) {
                    tsMin = tensionMin.get(0);
                }
                List<Double> elMaxNum = predictKv.getEl_max();
                if (null != elMaxNum && elMaxNum.size() > 0) {
                    elMax = elMaxNum.get(0);
                }
                List<Double> elMinNum = predictKv.getEl_min();
                if (null != elMinNum && elMinNum.size() > 0) {
                    elMin = elMinNum.get(0);
                }
                totalValue.getAndIncrement();
                //比较上下限和预测值大小，统计合格/不合格卷数
                //总数：屈服 抗拉 延伸
                //合格数：屈服 抗拉 延伸
                //不合格数：屈服 抗拉 延伸
                if (null != predictYs && predictYs != 0) {
                    if (null != ysMax && null != ysMin) {
                        if (predictYs >= ysMin && predictYs <= ysMax) {
                            //合格
                            yield_number_true++;
                        } else {
                            yield_number_false++;
                            ysFalseMatNo.add(coilNo);
                        }
                    } else {
                        yield_number_true++;
                    }
                } else {
                    yield_number_true++;
                }
                if (null != predictTs && predictTs != 0) {
                    if (null != tsMax && null != tsMin) {
                        if (predictTs >= tsMin && predictTs <= tsMax) {
                            //合格
                            tension_number_true++;
                        } else {
                            tension_number_false++;
                            tsFalseMatNo.add(coilNo);
                        }
                    } else {
                        tension_number_true++;
                    }
                } else {
                    tension_number_true++;
                }
                if (null != predictEl && predictEl != 0) {
                    if (null != elMax && null != elMin) {
                        if (predictEl >= elMin && predictEl <= elMax) {
                            //合格
                            el_number_true++;
                        } else {
                            el_number_false++;
                            elFalseMatNo.add(coilNo);
                        }
                    } else {
                        el_number_true++;
                    }
                } else {
                    el_number_true++;
                }
                //合格率 ：屈服 抗拉 延伸
                Boolean flag = true;
                if (predictYs != null) {
                    if (null != ysMax && null != ysMin) {
                        if (!(predictYs >= ysMin && predictYs <= ysMax)) {
                            flag = false;
                        }
                    }
                }
                if (!flag) {
                    continue;
                }
                if (predictTs != null) {
                    if (null != tsMax && null != tsMin) {
                        if (!(predictTs >= tsMin && predictTs <= tsMax)) {
                            flag = false;
                        }
                    }
                }
                if (!flag) {
                    continue;
                }
                if (predictEl != null) {
                    if (null != elMax && null != elMin) {
                        if (!(predictEl >= elMin && predictEl <= elMax)) {
                            flag = false;
                        }
                    }
                }
                if (!flag) {
                    continue;
                }
                m++;
            }

            JSONArray steed_grad_Datas = new JSONArray();
            steed_grade_map.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).limit(10).forEach(
                    (e) -> {
                        KeyValueObject kvo = new KeyValueObject();
                        kvo.setName(e.getKey());
                        kvo.setValue(e.getValue());
                        steed_grad_Datas.add(kvo);
                    });
            if (steed_grade_map.size() > 10) {
                int sum = steed_grade_map.entrySet().stream().sorted((o1, o2) -> o2.getValue() - o1.getValue()).skip(10).
                        limit(steed_grade_map.size()).map(en -> en.getValue()).mapToInt(o -> o.intValue()).sum();
                KeyValueObject kvo = new KeyValueObject();
                kvo.setName("other");
                kvo.setValue(sum);
                steed_grad_Datas.add(kvo);
            }

            JSONObject data = new JSONObject();
            JSONArray tableData = new JSONArray();
            CoilObject co = new CoilObject();
            co.setIndex("不合格卷数[卷]");
            co.setYs(yield_number_false);
            co.setTs(tension_number_false);
            co.setEl(el_number_false);
            co.setElFalseMatNo(elFalseMatNo);
            co.setTsFalseMatNo(tsFalseMatNo);
            co.setYsFalseMatNo(ysFalseMatNo);
            tableData.add(co);
            CoilObject co1 = new CoilObject();
            co1.setIndex("合格率[%]");
            if (totalValue.get() == 0) {
                data.put("passRate", null);
                co1.setYs(null);
                co1.setTs(null);
                co1.setEl(null);
            } else {
                BigDecimal passRate = getNumber(m).divide(getNumber(totalValue.get()), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
                data.put("passRate", passRate);

                co1.setYs(getNumber(yield_number_true).divide(getNumber(totalValue.get()), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
                co1.setTs(getNumber(tension_number_true).divide(getNumber(totalValue.get()), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
                co1.setEl(getNumber(el_number_true).divide(getNumber(totalValue.get()), 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
            }
            tableData.add(co1);

            data.put("coilNum", totalValue);
            data.put("steed_grade", steed_grad_Datas);
            data.put("tableData", tableData);
            return ResultData.ResultDataSuccess(data);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData sampTable(JSONObject content, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(content.toString(), RequestContent.class);
        // 获取数据中心数据
        JSONObject resultData = baseCalServiceSampTable(rc);
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");

        //异步获取total
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            try {
                return getCountSampleTable(rc);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        });

        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            JSONArray resultDatas = new JSONArray();
            for (JSONObject result : resultList) {
                JSONObject json = new JSONObject();
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                Double predictYs = null;
                Double predictTs = null;
                Double predictEl = null;
                Double predictR = null;
                Double predictN = null;
                try {
                    JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                    Kv gaCglpdoKv = response.getGA().getCglPdo().getKvs().getKv();
                    Kv gaMppKv = response.getGA().getMpp().getKvs().getKv();
                    Kv gaCglpdiKv = response.getGA().getCglPdi().getKvs().getKv();
                    Kv gaPredictKv = response.getGA().getPredict().getKvs().getKv();
                    Kv hsmHsmpdoKv = response.getHSM().getHSM_PDO().getKvs().getKv();
                    Kv pltcmMppKv = response.getPLTCM().getMpp().getKvs().getKv();
                    Kv pltcmPdiKv = response.getPLTCM().getMpp().getKvs().getKv();
                    List<String> coilId1 = pltcmMppKv.getCoil_id1();
                    if (null != coilId1 && coilId1.size() > 0) {
                        json.put("coilId1", coilId1.get(0));
                    } else {
                        json.put("coilId1", null);
                    }
                    List<String> coilNoOutList = gaCglpdoKv.getCoil_no_out();
                    if (null != coilNoOutList && coilNoOutList.size() > 0) {
                        json.put("coil_no_out", coilNoOutList.get(0));
                    } else {
                        json.put("coil_no_out", null);
                    }
                    List<Double> thicknessOutList = gaCglpdoKv.getThickness_out();
                    if (null != thicknessOutList && thicknessOutList.size() > 0) {
                        json.put("thickness_out", thicknessOutList.get(0));
                    } else {
                        json.put("thickness_out", null);
                    }
                    List<Double> tlElongList = gaCglpdoKv.getTl_elong();
                    if (null != tlElongList && tlElongList.size() > 0) {
                        json.put("tl_elong", tlElongList.get(0));
                    } else {
                        json.put("tl_elong", null);
                    }
                    List<Double> spmElongList = gaCglpdoKv.getSpm_elong();
                    if (null != spmElongList && spmElongList.size() > 0) {
                        json.put("spm_elong", spmElongList.get(0));
                    } else {
                        json.put("spm_elong", null);
                    }

                    List<String> shopSignCode = gaCglpdoKv.getShop_sign_code();
                    if (null != shopSignCode && shopSignCode.size() > 0) {
                        json.put("shop_sign_code", shopSignCode.get(0));
                    } else {
                        json.put("shop_sign_code", null);
                    }

                    List<String> productTime = gaCglpdoKv.getProduct_time();
                    if (null != productTime && productTime.size() > 0) {
                        String s = productTime.get(0);
                        json.put("product_time", s); //生产结束时间
                    } else {
                        json.put("product_time", null);
                    }
                    List<Double> widthOut = gaCglpdoKv.getWidth_out();
                    if (null != widthOut && widthOut.size() > 0) {
                        json.put("width_out", widthOut.get(0));
                    } else {
                        json.put("width_out", null);
                    }

                    List<String> sampleDirectionHa1List = pltcmPdiKv.getSample_direction_ha1();
                    if (null != sampleDirectionHa1List && sampleDirectionHa1List.size() > 0) {
                        json.put("sample_direction_ha1", sampleDirectionHa1List.get(0));
                    } else {
                        json.put("sample_direction_ha1", null);
                    }
                    List<Double> realTopYs1List = gaMppKv.getReal_top_ys1();
                    if (null != realTopYs1List && realTopYs1List.size() > 0) {
                        json.put("real_top_ys1", realTopYs1List.get(0));
                    } else {
                        json.put("real_top_ys1", null);
                    }
                    List<Double> realBomYs1List = gaMppKv.getReal_bom_ys1();
                    if (null != realBomYs1List && realBomYs1List.size() > 0) {
                        json.put("real_bom_ys1", realBomYs1List.get(0));
                    } else {
                        json.put("real_bom_ys1", null);
                    }
                    List<Double> realYs1List = pltcmPdiKv.getReal_ys1();
                    if (null != realYs1List && realYs1List.size() > 0) {
                        json.put("real_ys1", realYs1List.get(0));
                    } else {
                        json.put("real_ys1", null);
                    }
                    List<Double> realTs1List = pltcmPdiKv.getReal_ts1();
                    if (null != realTs1List && realTs1List.size() > 0) {
                        json.put("real_ts1", realTs1List.get(0));
                    } else {
                        json.put("real_ts1", null);
                    }
                    List<Double> realEl1List = pltcmPdiKv.getReal_el1();
                    if (null != realEl1List && realEl1List.size() > 0) {
                        json.put("real_el1", realEl1List.get(0));
                    } else {
                        json.put("real_el1", null);
                    }
                    List<Double> realR1List = pltcmPdiKv.getReal_r1();
                    if (null != realR1List && realR1List.size() > 0) {
                        json.put("real_r1", realR1List.get(0));
                    } else {
                        json.put("real_r1", null);
                    }
                    List<Double> realN1List = pltcmPdiKv.getReal_n1();
                    if (null != realN1List && realN1List.size() > 0) {
                        json.put("real_n1", realN1List.get(0));
                    } else {
                        json.put("real_n1", null);
                    }
                    List<String> samplePos1List = pltcmPdiKv.getSample_pos1();
                    if (null != samplePos1List && samplePos1List.size() > 0) {
                        json.put("sample_pos1", samplePos1List.get(0));
                    } else {
                        json.put("sample_pos1", null);
                    }
                    List<Double> sampleModeList = gaCglpdiKv.getSample_mode();
                    if (null != sampleModeList && sampleModeList.size() > 0) {
                        json.put("sample_mode", sampleModeList.get(0));
                    } else {
                        json.put("sample_mode", null);
                    }
                    List<String> hotCoilNoList = gaCglpdiKv.getHot_coil_no();
                    if (null != hotCoilNoList && hotCoilNoList.size() > 0) {
                        json.put("hot_coil_no", hotCoilNoList.get(0));
                    } else {
                        json.put("hot_coil_no", null);
                    }

                    List<Double> predictPointYsList = gaPredictKv.getPredict_point_ys();
                    if (null != predictPointYsList && predictPointYsList.size() > 0) {
                        json.put("predict_ys", predictPointYsList.get(0));
                        predictYs = predictPointYsList.get(0);
                    } else {
                        json.put("predict_ys", null);
                    }
                    List<Double> passRateYsList = gaPredictKv.getPass_rate_ys();
                    if (null != passRateYsList && passRateYsList.size() > 0) {
                        json.put("pass_rate_ys", passRateYsList.get(0));
                    } else {
                        json.put("pass_rate_ys", null);
                    }
                    List<Double> yieldMaxList = gaPredictKv.getYield_max();
                    if (null != yieldMaxList && yieldMaxList.size() > 0) {
                        json.put("yield_max", yieldMaxList.get(0));
                    } else {
                        json.put("yield_max", null);
                    }
                    List<Double> yieldMinList = gaPredictKv.getYield_min();
                    if (null != yieldMinList && yieldMinList.size() > 0) {
                        json.put("yield_min", yieldMinList.get(0));
                    } else {
                        json.put("yield_min", null);
                    }

                    List<Double> predictPointTsList = gaPredictKv.getPredict_point_ts();
                    if (null != predictPointTsList && predictPointTsList.size() > 0) {
                        json.put("predict_ts", predictPointTsList.get(0));
                        predictTs = predictPointTsList.get(0);
                    } else {
                        json.put("predict_ts", null);
                    }
                    List<Double> passRateTsList = gaPredictKv.getPass_rate_ts();
                    if (null != passRateTsList && passRateTsList.size() > 0) {
                        json.put("pass_rate_ts", passRateTsList.get(0));
                    } else {
                        json.put("pass_rate_ts", null);
                    }
                    List<Double> tensionMaxList = gaPredictKv.getTension_max();
                    if (null != tensionMaxList && tensionMaxList.size() > 0) {
                        json.put("tension_max", tensionMaxList.get(0));
                    } else {
                        json.put("tension_max", null);
                    }
                    List<Double> tensionMinList = gaPredictKv.getTension_min();
                    if (null != tensionMinList && tensionMinList.size() > 0) {
                        json.put("tension_min", tensionMinList.get(0));
                    } else {
                        json.put("tension_min", null);
                    }

                    List<Double> predictPointElList = gaPredictKv.getPredict_point_el();
                    if (null != predictPointElList && predictPointElList.size() > 0) {
                        json.put("predict_el", predictPointElList.get(0));
                        predictEl = predictPointElList.get(0);
                    } else {
                        json.put("predict_el", null);
                    }
                    List<Double> passRateElList = gaPredictKv.getPass_rate_el();
                    if (null != passRateElList && passRateElList.size() > 0) {
                        json.put("pass_rate_el", passRateElList.get(0));
                    } else {
                        json.put("pass_rate_el", null);
                    }
                    List<Double> elMaxList = gaPredictKv.getEl_max();
                    if (null != elMaxList && elMaxList.size() > 0) {
                        json.put("el_max", elMaxList.get(0));
                    } else {
                        json.put("el_max", null);
                    }
                    List<Double> elMinList = gaPredictKv.getEl_min();
                    if (null != elMinList && elMinList.size() > 0) {
                        json.put("el_min", elMinList.get(0));
                    } else {
                        json.put("el_min", null);
                    }

                    List<Double> predictPointRList = gaPredictKv.getPredict_point_r();
                    if (null != predictPointRList && predictPointRList.size() > 0) {
                        json.put("predict_r", predictPointRList.get(0));
                        predictR = predictPointRList.get(0);
                    } else {
                        json.put("predict_r", null);
                    }
                    List<Double> passRateRList = gaPredictKv.getPass_rate_r();
                    if (null != passRateRList && passRateRList.size() > 0) {
                        json.put("pass_rate_r", passRateRList.get(0));
                    } else {
                        json.put("pass_rate_r", null);
                    }
                    List<Double> rMinList = gaPredictKv.getR_min();
                    if (null != rMinList && rMinList.size() > 0) {
                        json.put("r_min", rMinList.get(0));
                    } else {
                        json.put("r_min", null);
                    }
                    List<Double> rMaxList = gaPredictKv.getR_max();
                    if (null != rMaxList && rMaxList.size() > 0) {
                        json.put("r_max", rMaxList.get(0));
                    } else {
                        json.put("r_max", null);
                    }

                    List<Double> predictPointNList = gaPredictKv.getPredict_point_n();
                    if (null != predictPointNList && predictPointNList.size() > 0) {
                        json.put("predict_n", predictPointNList.get(0));
                        predictN = predictPointNList.get(0);
                    } else {
                        json.put("predict_n", null);
                    }
                    List<Double> passRateNList = gaPredictKv.getPass_rate_n();
                    if (null != passRateNList && passRateNList.size() > 0) {
                        json.put("pass_rate_n", passRateNList.get(0));
                    } else {
                        json.put("pass_rate_n", null);
                    }
                    List<Double> nMaxList = gaPredictKv.getN_max();
                    if (null != nMaxList && nMaxList.size() > 0) {
                        json.put("n_max", nMaxList.get(0));
                    } else {
                        json.put("n_max", null);
                    }
                    List<Double> nMinList = gaPredictKv.getN_min();
                    if (null != nMinList && nMinList.size() > 0) {
                        json.put("n_min", nMinList.get(0));
                    } else {
                        json.put("n_min", null);
                    }

                    List<Double> sizeProductLenList = hsmHsmpdoKv.getSize_product_len();
                    if (null != sizeProductLenList && sizeProductLenList.size() > 0) {
                        json.put("size_product_len", sizeProductLenList.get(0));
                    } else {
                        json.put("size_product_len", null);
                    }

                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
                resultDatas.add(json);
            }
            JSONObject data = new JSONObject();
            data.put("tableData", resultDatas);
//            // 计算总条数 添加
            Integer total = future.join();
            data.put("total", total);
            return ResultData.ResultDataSuccess(data, null);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData processLine(JSONObject jsonObject, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(jsonObject.toString(), RequestContent.class);
        String coilNoOut = rc.getCoil_no_out();
        JSONObject calTemp = new JSONObject();
        JSONObject lm = new JSONObject();
        JSONObject hsm = new JSONObject();
        JSONObject data = new JSONObject();
        JSONObject predict = new JSONObject();
        JSONObject lm1 = new JSONObject();
        JSONObject lm2 = new JSONObject();
        List<String> typeList = Arrays.asList("predict_ys", "predict_ts", "predict_el", "predict_r", "predict_n");
        List<String> calTempList = Arrays.asList("ph_temp_act", "rtf1_temp_act", "rtf2_temp_act", "rtf3_temp_act", "rtf4_temp_act", "rtf5_temp_act"
                , "rtf6_temp_act", "rtf7_temp_act", "rcs_temp_act", "sf_temp_act");
        List<String> lmList = Arrays.asList("elong_act", "process_speed_act");


        String fake = "{\"data\":[],\"length\":[]}";
        JSONObject fakeJsonObj = JSON.parseObject(fake);
        for (String s : typeList) {
            // 获取数据中心数据
            JSONObject resultData = baseCalServiceProcessLinefor(coilNoOut, s);
            // 读取数据中心数据
            Integer code = resultData.getInteger("code");
            if (code == 200) {
                List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
                if (null != resultList && resultList.size() > 0) {
                    JSONObject jsonObject1 = resultList.get(0);
                    JSONObject data1 = jsonObject1.getJSONObject("data");
                    predict.put(s, data1);
                } else {
                    predict.put(s, fakeJsonObj);
                }
            }
        }
        for (String s : calTempList) {
            // 获取数据中心数据
            JSONObject resultData = baseCalServiceProcessLinefor(coilNoOut, s);
            // 读取数据中心数据
            Integer code = resultData.getInteger("code");
            if (code == 200) {
                List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
                if (null != resultList && resultList.size() > 0) {
                    JSONObject jsonObject1 = resultList.get(0);
                    JSONObject data1 = jsonObject1.getJSONObject("data");
                    if (s.equals("ph_temp_act")) {
                        calTemp.put("gl_fce_preheat_te112_act", data1);
                    } else if (s.equals("rcs_temp_act")) {
                        calTemp.put("gl_fastcool_bot_temp_act", data1);
                    } else if (s.equals("sf_temp_act")) {
                        calTemp.put("gl_fce_balanced_temp_act", data1);
                    } else {
                        calTemp.put("gl_fce_" + s, data1);
                    }
                } else {
                    if (s.equals("ph_temp_act")) {
                        calTemp.put("gl_fce_preheat_te112_act", fakeJsonObj);
                    } else if (s.equals("rcs_temp_act")) {
                        calTemp.put("gl_fastcool_bot_temp_act", fakeJsonObj);
                    } else if (s.equals("sf_temp_act")) {
                        calTemp.put("gl_fce_balanced_temp_act", fakeJsonObj);
                    } else {
                        calTemp.put("gl_fce_" + s, fakeJsonObj);
                    }
                }
            }
        }
        for (String s : lmList) {
            // 获取数据中心数据
            JSONObject resultData = baseCalServiceProcessLinefor(coilNoOut, s);
            // 读取数据中心数据
            Integer code = resultData.getInteger("code");
            if (code == 200) {
                List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
                if (null != resultList && resultList.size() > 0) {
                    JSONObject jsonObject1 = resultList.get(0);
                    JSONObject data1 = jsonObject1.getJSONObject("data");
                    if (s.equals("elong_act")) {
                        lm.put("gl_spm_elong_act", data1);
                    } else {
                        lm.put("gl_process_speed_act", data1);
                    }
                } else {
                    if (s.equals("elong_act")) {
                        lm.put("gl_spm_elong_act", fakeJsonObj);
                    } else {
                        lm.put("gl_process_speed_act", fakeJsonObj);
                    }
                }
            }
        }
        List<String> hsm2List = Arrays.asList("hsm2_r2dt_b", "hsm2_fdt_b", "hsm2_ctc_bh");
        List<String> hsm1List = Arrays.asList("hsm1_r1dt_b", "hsm1_fdt_b", "hsm1_ctc");
        String hotCoilNo = "";
        JSONObject hotTypeData = baseCalServiceGetHotType(coilNoOut);
        // 读取数据中心数据
        Integer code = hotTypeData.getInteger("code");
        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(hotTypeData.getJSONArray("results")), JSONObject.class);
            if (null != resultList && resultList.size() > 0) {
                JSONObject jsonObject1 = resultList.get(0);
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = jsonObject1.toJSONString();
                JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                Kv gaCglpdiKv = response.getGA().getCglPdi().getKvs().getKv();
                List<String> hotCoilNoList = gaCglpdiKv.getHot_coil_no();
                if (null != hotCoilNoList && hotCoilNoList.size() > 0) {
                    hotCoilNo = hotCoilNoList.get(0);
                }
            }
        }
        String firstNum = "";
        if (StringUtils.isNotBlank(hotCoilNo)) {
            firstNum = hotCoilNo.substring(0, 1);
        }
        if (StringUtils.isNotBlank(firstNum)) {
            if ("1".equals(firstNum)) { //hsm1
                for (String s : hsm1List) {
                    // 获取数据中心数据
                    JSONObject resultData = baseCalServiceProcessLinefor(coilNoOut, s);
                    // 读取数据中心数据
                    Integer code2 = resultData.getInteger("code");
                    if (code2 == 200) {
                        List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
                        if (null != resultList && resultList.size() > 0) {
                            JSONObject jsonObject1 = resultList.get(0);
                            JSONObject data1 = jsonObject1.getJSONObject("data");
                            hsm.put("s", data1);
                        } else {
                            hsm.put("s", fakeJsonObj);
                        }
                    }
                }
            } else if ("2".equals(firstNum)) {//hsm2
                for (String s : hsm2List) {
                    // 获取数据中心数据
                    JSONObject resultData = baseCalServiceProcessLinefor(coilNoOut, s);
                    // 读取数据中心数据
                    Integer code2 = resultData.getInteger("code");
                    if (code2 == 200) {
                        List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
                        if (null != resultList && resultList.size() > 0) {
                            JSONObject jsonObject1 = resultList.get(0);
                            JSONObject data1 = jsonObject1.getJSONObject("data");
                            hsm.put(s, data1);
                        } else {
                            hsm.put(s, fakeJsonObj);
                        }
                    }
                }
            }
        }

        lm1.put("gl_spm_elong_act",lm.get("gl_spm_elong_act"));
        lm2.put("gl_process_speed_act",lm.get("gl_process_speed_act"));
        JSONObject json = new JSONObject();
        JSONObject resultData = baseCalServiceProcessLineMaxAndMin(coilNoOut);
        // 读取数据中心数据
        Integer code3 = resultData.getInteger("code");
        if (code3 == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            if(null!= resultList && resultList.size()>0){
                for (JSONObject result : resultList) {
                    ObjectMapper objectMapper = new ObjectMapper();
                    String jsonString = result.toJSONString();
                    JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                    Kv gaPredictKv = response.getGA().getPredict().getKvs().getKv();
                    List<Double> yieldMaxList = gaPredictKv.getYield_max();
                    if (null != yieldMaxList && yieldMaxList.size() > 0) {
                        json.put("yield_max", yieldMaxList.get(0));
                    } else {
                        json.put("yield_max", null);
                    }
                    List<Double> yieldMinList = gaPredictKv.getYield_min();
                    if (null != yieldMinList && yieldMinList.size() > 0) {
                        json.put("yield_min", yieldMinList.get(0));
                    } else {
                        json.put("yield_min", null);
                    }

                    List<Double> tensionMaxList = gaPredictKv.getTension_max();
                    if (null != tensionMaxList && tensionMaxList.size() > 0) {
                        json.put("tension_max", tensionMaxList.get(0));
                    } else {
                        json.put("tension_max", null);
                    }
                    List<Double> tensionMinList = gaPredictKv.getTension_min();
                    if (null != tensionMinList && tensionMinList.size() > 0) {
                        json.put("tension_min", tensionMinList.get(0));
                    } else {
                        json.put("tension_min", null);
                    }

                    List<Double> elMaxList = gaPredictKv.getEl_max();
                    if (null != elMaxList && elMaxList.size() > 0) {
                        json.put("el_max", elMaxList.get(0));
                    } else {
                        json.put("el_max", null);
                    }
                    List<Double> elMinList = gaPredictKv.getEl_min();
                    if (null != elMinList && elMinList.size() > 0) {
                        json.put("el_min", elMinList.get(0));
                    } else {
                        json.put("el_min", null);
                    }

                    List<Double> rMinList = gaPredictKv.getR_min();
                    if (null != rMinList && rMinList.size() > 0) {
                        json.put("r_min", rMinList.get(0));
                    } else {
                        json.put("r_min", null);
                    }
                    List<Double> rMaxList = gaPredictKv.getR_max();
                    if (null != rMaxList && rMaxList.size() > 0) {
                        json.put("r_max", rMaxList.get(0));
                    } else {
                        json.put("r_max", null);
                    }

                    List<Double> nMaxList = gaPredictKv.getN_max();
                    if (null != nMaxList && nMaxList.size() > 0) {
                        json.put("n_max", nMaxList.get(0));
                    } else {
                        json.put("n_max", null);
                    }
                    List<Double> nMinList = gaPredictKv.getN_min();
                    if (null != nMinList && nMinList.size() > 0) {
                        json.put("n_min", nMinList.get(0));
                    } else {
                        json.put("n_min", null);
                    }
                }
            }
        }


        data.put("Predict", predict);
        data.put("calTemp", calTemp);
        data.put("lm", lm);
        data.put("hsm", hsm);
        data.put("lm1", lm1);
        data.put("lm2", lm2);
        data.put("maxAndMin",json);
        return ResultData.ResultDataSuccess(data);
    }


    @Override
    public ResultData mppChange(JSONObject jsonObject, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(jsonObject.toString(), RequestContent.class);
        String coilNoOut = rc.getCoil_no_out();
        // 获取数据中心数据
        JSONObject resultData = baseCalServiceMppChange(coilNoOut);
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");
        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            JSONArray resultDatas = new JSONArray();
            for (JSONObject result : resultList) {
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                ArrayList<Double> reRateS1List = new ArrayList<>();
                ArrayList<Double> reRateS2List = new ArrayList<>();
                ArrayList<Double> reRateS3List = new ArrayList<>();
                ArrayList<Double> reRateS4List = new ArrayList<>();
                ArrayList<Double> reRateS5List = new ArrayList<>();
                ArrayList<Double> reductionRateList = new ArrayList<>();
                ArrayList<Double> rtf1TempAct2List = new ArrayList<>();
                ArrayList<Double> rtf2TempAct2List = new ArrayList<>();
                ArrayList<Double> rtf3TempAct2List = new ArrayList<>();
                ArrayList<Double> rtf4TempAct2List = new ArrayList<>();
                ArrayList<Double> rtf5TempAct2List = new ArrayList<>();
                ArrayList<Double> rtf6TempAct2List = new ArrayList<>();
                ArrayList<Double> rtf7TempAct2List = new ArrayList<>();
                ArrayList<Double> phTempAct2List = new ArrayList<>();
                ArrayList<Double> sfTempAct2List = new ArrayList<>();
                ArrayList<Double> elongAct2List = new ArrayList<>();
                ArrayList<Double> processSpeedAct2List = new ArrayList<>();
                try {
                    JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                    Kv pltcmPltcmKv = response.getPLTCM().getPLTCM_PDO().getKvs().getKv();
                    Kv predictKv = response.getGA().getPredict().getKvs().getKv();
                    Kv cglPdoKv = response.getGA().getCglPdo().getKvs().getKv();
                    List<String> shopSignCodeList = cglPdoKv.getShop_sign_code();
                    String shopSignCode = null;
                    if (null != shopSignCodeList && shopSignCodeList.size() > 0) {
                        shopSignCode = shopSignCodeList.get(0);
                        JSONObject resultData2 = baseCalServiceMppChange3(shopSignCode);
                        Integer code2 = resultData2.getInteger("code");
                        if (code2 == 200) {
                            List<JSONObject> resultList2 = JSONArray.parseArray(JSON.toJSONString(resultData2.getJSONArray("results")), JSONObject.class);
                            for (JSONObject result2 : resultList2) {
                                String jsonString2 = result2.toJSONString();
                                JsonResponse response2 = objectMapper.readValue(jsonString2, JsonResponse.class);
                                Kv pltcmPltcmKv2 = response2.getPLTCM().getPLTCM_PDO().getKvs().getKv();
                                Kv predictKv2 = response2.getGA().getPredict().getKvs().getKv();
                                List<Double> reductionRate2S1 = pltcmPltcmKv2.getReduction_rate_s1();
                                List<Double> reductionRate2S2 = pltcmPltcmKv2.getReduction_rate_s2();
                                List<Double> reductionRate2S3 = pltcmPltcmKv2.getReduction_rate_s3();
                                List<Double> reductionRate2S4 = pltcmPltcmKv2.getReduction_rate_s4();
                                List<Double> reductionRate2S5 = pltcmPltcmKv2.getReduction_rate_s5();
                                List<Double> infoThick2 = null;
                                List<Double> infoAimThick2 = null;
                                infoThick2 = pltcmPltcmKv2.getInfo_thick();//入口厚度
                                infoAimThick2 = pltcmPltcmKv2.getInfo_aim_thick();//出口目标厚度
                                Double reductionRate2 = null;
                                if ((null != infoThick2 && !infoThick2.isEmpty() && infoThick2.size() > 0)
                                        && (null != infoAimThick2 && !infoAimThick2.isEmpty() && infoAimThick2.size() > 0)) {
                                    Double in2 = infoThick2.get(0);
                                    Double out2 = infoAimThick2.get(0);
                                    if (null != in2 && null != out2) {
                                        reductionRate2 = (in2 - out2) / in2;
                                    }
                                }
                                List<Double> rtf1TempAct2 = predictKv2.getRtf1_temp_act();
                                List<Double> rtf2TempAct2 = predictKv2.getRtf2_temp_act();
                                List<Double> rtf3TempAct2 = predictKv2.getRtf3_temp_act();
                                List<Double> rtf4TempAct2 = predictKv2.getRtf4_temp_act();
                                List<Double> rtf5TempAct2 = predictKv2.getRtf5_temp_act();
                                List<Double> rtf6TempAct2 = predictKv2.getRtf6_temp_act();
                                List<Double> rtf7TempAct2 = predictKv2.getRtf7_temp_act();
                                List<Double> phTempAct2 = predictKv2.getPh_temp_act();
                                List<Double> sfTempAct2 = predictKv2.getSf_temp_act();
                                List<Double> elongAct2 = predictKv2.getElong_act();
                                List<Double> processSpeedAct2 = predictKv2.getProcess_speed_act();

                                if (null != reductionRate2S1 && reductionRate2S1.size() > 0) {
                                    Double v = reductionRate2S1.get(0);
                                    if (null != v) {
                                        log.info("rerateS1" + v);
                                        if (v > 0 && v < 100) {
                                            reRateS1List.add(v);
                                        }
                                    }
                                }
                                if (null != reductionRate2S2 && reductionRate2S2.size() > 0) {
                                    Double v = reductionRate2S2.get(0);
                                    if (v > 0 && v < 100) {
                                        reRateS2List.add(v);
                                    }
                                }
                                if (null != reductionRate2S3 && reductionRate2S3.size() > 0) {
                                    Double v = reductionRate2S3.get(0);
                                    if (v > 0 && v < 100) {
                                        reRateS3List.add(v);
                                    }
                                }
                                if (null != reductionRate2S4 && reductionRate2S4.size() > 0) {
                                    Double v = reductionRate2S4.get(0);
                                    if (v > 0 && v < 100) {
                                        reRateS4List.add(v);
                                    }
                                }
                                if (null != reductionRate2S5 && reductionRate2S5.size() > 0) {
                                    Double v = reductionRate2S5.get(0);
                                    if (v > 0 && v < 100) {
                                        reRateS5List.add(v);
                                    }
                                }
                                if (null != reductionRate2) {
                                    reductionRateList.add(reductionRate2);
                                }
                                //
                                if (null != rtf1TempAct2 && rtf1TempAct2.size() > 0) {
                                    Double v = rtf1TempAct2.get(0);
                                    rtf1TempAct2List.add(v);
                                }
                                if (null != rtf2TempAct2 && rtf2TempAct2.size() > 0) {
                                    Double v = rtf2TempAct2.get(0);
                                    rtf2TempAct2List.add(v);
                                }
                                if (null != rtf3TempAct2 && rtf3TempAct2.size() > 0) {
                                    Double v = rtf3TempAct2.get(0);
                                    rtf3TempAct2List.add(v);
                                }
                                if (null != rtf4TempAct2 && rtf4TempAct2.size() > 0) {
                                    Double v = rtf4TempAct2.get(0);
                                    rtf4TempAct2List.add(v);
                                }
                                if (null != rtf5TempAct2 && rtf5TempAct2.size() > 0) {
                                    Double v = rtf5TempAct2.get(0);
                                    rtf5TempAct2List.add(v);
                                }
                                if (null != rtf6TempAct2 && rtf6TempAct2.size() > 0) {
                                    Double v = rtf6TempAct2.get(0);
                                    rtf6TempAct2List.add(v);
                                }
                                if (null != rtf7TempAct2 && rtf7TempAct2.size() > 0) {
                                    Double v = rtf7TempAct2.get(0);
                                    rtf7TempAct2List.add(v);
                                }
                                if (null != phTempAct2 && phTempAct2.size() > 0) {
                                    Double v = phTempAct2.get(0);
                                    phTempAct2List.add(v);
                                }
                                if (null != sfTempAct2 && sfTempAct2.size() > 0) {
                                    Double v = sfTempAct2.get(0);
                                    sfTempAct2List.add(v);
                                }
                                if (null != elongAct2 && elongAct2.size() > 0) {
                                    Double v = elongAct2.get(0);
                                    elongAct2List.add(v);
                                }
                                if (null != processSpeedAct2 && processSpeedAct2.size() > 0) {
                                    Double v = processSpeedAct2.get(0);
                                    processSpeedAct2List.add(v);
                                }
                            }

                        }

                    }
                    Double s1Avg = null;
                    Double s2Avg = null;
                    Double s3Avg = null;
                    Double s4Avg = null;
                    Double s5Avg = null;
                    Double rrAvg = null;
                    Double ra1Avg = null;
                    Double ra2Avg = null;
                    Double ra3Avg = null;
                    Double ra4Avg = null;
                    Double ra5Avg = null;
                    Double ra6Avg = null;
                    Double ra7Avg = null;
                    Double phAvg = null;
                    Double saAvg = null;
                    Double eaAvg = null;
                    Double psaAvg = null;
                    if (null != reRateS1List && reRateS1List.size() > 0) {
                        int c = 0;
                        for (Double d : reRateS1List) {
                            c++;
                            log.info("遍历S1" + c + "," + d);
                        }
                        s1Avg = reRateS1List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != reRateS2List && reRateS2List.size() > 0) {
                        s2Avg = reRateS2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != reRateS3List && reRateS3List.size() > 0) {
                        s3Avg = reRateS3List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != reRateS4List && reRateS4List.size() > 0) {
                        s4Avg = reRateS4List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != reRateS5List && reRateS5List.size() > 0) {
                        s5Avg = reRateS5List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != reductionRateList && reductionRateList.size() > 0) {
                        rrAvg = reductionRateList.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != rtf1TempAct2List && rtf1TempAct2List.size() > 0) {
                        ra1Avg = rtf1TempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != rtf2TempAct2List && rtf2TempAct2List.size() > 0) {
                        ra2Avg = rtf2TempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != rtf3TempAct2List && rtf3TempAct2List.size() > 0) {
                        ra3Avg = rtf3TempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != rtf4TempAct2List && rtf4TempAct2List.size() > 0) {
                        ra4Avg = rtf4TempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != rtf5TempAct2List && rtf5TempAct2List.size() > 0) {
                        ra5Avg = rtf5TempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != rtf6TempAct2List && rtf6TempAct2List.size() > 0) {
                        ra6Avg = rtf6TempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != rtf7TempAct2List && rtf7TempAct2List.size() > 0) {
                        ra7Avg = rtf7TempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != phTempAct2List && phTempAct2List.size() > 0) {
                        phAvg = phTempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != sfTempAct2List && sfTempAct2List.size() > 0) {
                        saAvg = sfTempAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != elongAct2List && elongAct2List.size() > 0) {
                        eaAvg = elongAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }
                    if (null != processSpeedAct2List && processSpeedAct2List.size() > 0) {
                        psaAvg = processSpeedAct2List.stream().mapToDouble(Double::doubleValue).average().orElse(0.0);
                    }

                    List<Double> reductionRateS1 = pltcmPltcmKv.getReduction_rate_s1();
                    if (null != reductionRateS1 && reductionRateS1.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "1机架压下量");
                        json.put("act", reductionRateS1.get(0));
                        json.put("avg", s1Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "1机架压下量");
                        json.put("act", null);
                        json.put("avg", s1Avg);
                        resultDatas.add(json);
                    }
                    List<Double> reductionRateS2 = pltcmPltcmKv.getReduction_rate_s2();
                    if (null != reductionRateS2 && reductionRateS2.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "2机架压下量");
                        json.put("act", reductionRateS2.get(0));
                        json.put("avg", s2Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "2机架压下量");
                        json.put("act", null);
                        json.put("avg", s2Avg);
                        resultDatas.add(json);
                    }
                    List<Double> reductionRateS3 = pltcmPltcmKv.getReduction_rate_s3();
                    if (null != reductionRateS3 && reductionRateS3.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "3机架压下量");
                        json.put("act", reductionRateS3.get(0));
                        json.put("avg", s3Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "3机架压下量");
                        json.put("act", null);
                        json.put("avg", s3Avg);
                        resultDatas.add(json);
                    }
                    List<Double> reductionRateS4 = pltcmPltcmKv.getReduction_rate_s4();
                    if (null != reductionRateS4 && reductionRateS4.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "4机架压下量");
                        json.put("act", reductionRateS4.get(0));
                        json.put("avg", s4Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "4机架压下量");
                        json.put("act", null);
                        json.put("avg", s4Avg);
                        resultDatas.add(json);
                    }
                    List<Double> reductionRateS5 = pltcmPltcmKv.getReduction_rate_s5();
                    if (null != reductionRateS5 && reductionRateS5.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "5机架压下量");
                        json.put("act", reductionRateS5.get(0));
                        json.put("avg", s5Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "5机架压下量");
                        json.put("act", null);
                        json.put("avg", s5Avg);
                        resultDatas.add(json);
                    }

                    List<Double> infoThick = pltcmPltcmKv.getInfo_thick();//入口厚度
                    List<Double> infoAimThick = pltcmPltcmKv.getInfo_aim_thick();//出口目标厚度

                    if (null != infoThick && infoThick.size() > 0
                            && null != infoAimThick && infoAimThick.size() > 0) {
                        Double in = infoThick.get(0);
                        Double out = infoAimThick.get(0);
                        Double reductionRate = (in - out) / in;

                        JSONObject json = new JSONObject();
                        json.put("process", "总压下率");
                        json.put("act", reductionRate);
                        json.put("avg", rrAvg);
                        resultDatas.add(json);
                    }

                    List<Double> phTempAct = predictKv.getPh_temp_act(); //预热pv值
                    if (null != phTempAct && phTempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "预热pv值");
                        json.put("act", phTempAct.get(0));
                        json.put("avg", phAvg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "预热pv值");
                        json.put("act", null);
                        json.put("avg", phAvg);
                        resultDatas.add(json);
                    }
                    List<Double> rtf1TempAct = predictKv.getRtf1_temp_act();//加热1段pv值
                    if (null != rtf1TempAct && rtf1TempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热1段pv值");
                        json.put("act", rtf1TempAct.get(0));
                        json.put("avg", ra1Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热1段pv值");
                        json.put("act", null);
                        json.put("avg", ra1Avg);
                        resultDatas.add(json);
                    }
                    List<Double> rtf2TempAct = predictKv.getRtf2_temp_act();
                    if (null != rtf2TempAct && rtf2TempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热2段pv值");
                        json.put("act", rtf2TempAct.get(0));
                        json.put("avg", ra2Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热2段pv值");
                        json.put("act", null);
                        json.put("avg", ra2Avg);
                        resultDatas.add(json);
                    }
                    List<Double> rtf3TempAct = predictKv.getRtf3_temp_act();
                    if (null != rtf3TempAct && rtf3TempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热3段pv值");
                        json.put("act", rtf3TempAct.get(0));
                        json.put("avg", ra3Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热3段pv值");
                        json.put("act", null);
                        json.put("avg", ra3Avg);
                        resultDatas.add(json);
                    }
                    List<Double> rtf4TempAct = predictKv.getRtf4_temp_act();
                    if (null != rtf4TempAct && rtf4TempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热4段pv值");
                        json.put("act", rtf4TempAct.get(0));
                        json.put("avg", ra4Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热4段pv值");
                        json.put("act", null);
                        json.put("avg", ra4Avg);
                        resultDatas.add(json);
                    }
                    List<Double> rtf5TempAct = predictKv.getRtf5_temp_act();
                    if (null != rtf5TempAct && rtf5TempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热5段pv值");
                        json.put("act", rtf5TempAct.get(0));
                        json.put("avg", ra5Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热5段pv值");
                        json.put("act", null);
                        json.put("avg", ra5Avg);
                        resultDatas.add(json);
                    }
                    List<Double> rtf6TempAct = predictKv.getRtf6_temp_act();
                    if (null != rtf6TempAct && rtf6TempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热6段pv值");
                        json.put("act", rtf6TempAct.get(0));
                        json.put("avg", ra6Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热6段pv值");
                        json.put("act", null);
                        json.put("avg", ra6Avg);
                        resultDatas.add(json);
                    }
                    List<Double> rtf7TempAct = predictKv.getRtf7_temp_act();
                    if (null != rtf7TempAct && rtf7TempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热7段pv值");
                        json.put("act", rtf7TempAct.get(0));
                        json.put("avg", ra7Avg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "加热7段pv值");
                        json.put("act", null);
                        json.put("avg", ra7Avg);
                        resultDatas.add(json);
                    }
                    List<Double> sfTempAct = predictKv.getSf_temp_act();//均衡段pv值
                    if (null != sfTempAct && sfTempAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "均衡段pv值");
                        json.put("act", sfTempAct.get(0));
                        json.put("avg", saAvg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "均衡段pv值");
                        json.put("act", null);
                        json.put("avg", saAvg);
                        resultDatas.add(json);
                    }
                    List<Double> elongAct = predictKv.getElong_act();//光整延伸率实际值
                    if (null != elongAct && elongAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "光整延伸率实际值");
                        json.put("act", elongAct.get(0));
                        json.put("avg", eaAvg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "光整延伸率实际值");
                        json.put("act", null);
                        json.put("avg", eaAvg);
                        resultDatas.add(json);
                    }
                    List<Double> processSpeedAct = predictKv.getProcess_speed_act();//工艺段实际速度
                    if (null != processSpeedAct && processSpeedAct.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "工艺段实际速度");
                        json.put("act", processSpeedAct.get(0));
                        json.put("avg", psaAvg);
                        resultDatas.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "工艺段实际速度");
                        json.put("act", null);
                        json.put("avg", psaAvg);
                        resultDatas.add(json);
                    }
                } catch (JsonMappingException e) {
                    throw new RuntimeException(e);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            }
            JSONObject data = new JSONObject();


            data.put("PDO", resultDatas);
            Integer total = resultList.size();
            data.put("total", total);
            return ResultData.ResultDataSuccess(data, null);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData mppChange2(JSONObject jsonObject, String url) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(jsonObject.toString(), RequestContent.class);
        String coilNoOut = rc.getCoil_no_out();
        // 获取数据中心数据
        JSONObject resultData = baseCalServiceMppChange2(coilNoOut);
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");
        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            JSONArray jsonArray = new JSONArray();
            for (JSONObject result : resultList) {

                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                try {
                    JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                    Kv stlElementKv = response.getSTL().getElement().getKvs().getKv();
                    List<Double> chemAl = stlElementKv.getChem_al();
                    if (null != chemAl && chemAl.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "al");
                        json.put("data", chemAl.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "al");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemCa = stlElementKv.getChem_ca();
                    if (null != chemCa && chemCa.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "ca");
                        json.put("data", chemCa.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "ca");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemB = stlElementKv.getChem_b();
                    if (null != chemB && chemB.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "b");
                        json.put("data", chemB.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "b");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemAs = stlElementKv.getChem_as();
                    if (null != chemAs && chemAs.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "as");
                        json.put("data", chemAs.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "as");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemC = stlElementKv.getChem_c();
                    if (null != chemC && chemC.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "c");
                        json.put("data", chemC.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "c");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemCr = stlElementKv.getChem_cr();
                    if (null != chemCr && chemCr.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "cr");
                        json.put("data", chemCr.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "cr");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemH = stlElementKv.getChem_h();
                    if (null != chemH && chemH.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "h");
                        json.put("data", chemH.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "h");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemMn = stlElementKv.getChem_mn();
                    if (null != chemMn && chemMn.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "mn");
                        json.put("data", chemMn.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "mn");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemSi = stlElementKv.getChem_si();
                    if (null != chemSi && chemSi.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "si");
                        json.put("data", chemSi.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "si");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemP = stlElementKv.getChem_p();
                    if (null != chemP && chemP.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "p");
                        json.put("data", chemP.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "p");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemS = stlElementKv.getChem_s();
                    if (null != chemS && chemS.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "s");
                        json.put("data", chemS.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "s");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemCu = stlElementKv.getChem_cu();
                    if (null != chemCu && chemCu.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "cu");
                        json.put("data", chemCu.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "cu");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemNi = stlElementKv.getChem_ni();
                    if (null != chemNi && chemNi.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "ni");
                        json.put("data", chemNi.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "ni");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemMo = stlElementKv.getChem_mo();
                    if (null != chemMo && chemMo.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "mo");
                        json.put("data", chemMo.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "mo");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemNb = stlElementKv.getChem_nb();
                    if (null != chemNb && chemNb.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "nb");
                        json.put("data", chemNb.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "nb");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemV = stlElementKv.getChem_v();
                    if (null != chemV && chemV.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "v");
                        json.put("data", chemV.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "v");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemTi = stlElementKv.getChem_ti();
                    if (null != chemTi && chemTi.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "ti");
                        json.put("data", chemTi.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "ti");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemAl2Co33 = stlElementKv.getChem_al2_co3_3();
                    if (null != chemAl2Co33 && chemAl2Co33.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "al2co33");
                        json.put("data", chemAl2Co33.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "al2co33");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemN = stlElementKv.getChem_n();
                    if (null != chemN && chemN.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "n");
                        json.put("data", chemN.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "n");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemSn = stlElementKv.getChem_sn();
                    if (null != chemSn && chemSn.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "sn");
                        json.put("data", chemSn.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "sn");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemW = stlElementKv.getChem_w();
                    if (null != chemW && chemW.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "w");
                        json.put("data", chemW.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "w");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemZr = stlElementKv.getChem_zr();
                    if (null != chemZr && chemZr.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "zr");
                        json.put("data", chemZr.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "zr");
                        json.put("data", null);
                        jsonArray.add(json);
                    }
                    List<Double> chemO = stlElementKv.getChem_o();
                    if (null != chemO && chemO.size() > 0) {
                        JSONObject json = new JSONObject();
                        json.put("process", "o");
                        json.put("data", chemO.get(0));
                        jsonArray.add(json);
                    } else {
                        JSONObject json = new JSONObject();
                        json.put("process", "o");
                        json.put("data", null);
                        jsonArray.add(json);
                    }


                } catch (JsonMappingException e) {
                    throw new RuntimeException(e);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }
            }
            JSONObject data = new JSONObject();
            data.put("PDI", jsonArray);
            Integer total = resultList.size();
            data.put("total", total);
            return ResultData.ResultDataSuccess(data, null);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData getNewCoilId(JSONObject jsonObject, String path) {
        // 获取数据中心数据
        JSONObject resultData = baseCalServiceGetNewCoilId();
        // 读取数据中心数据
        Integer code = resultData.getInteger("code");
        //保存全部的钢卷号
        if (code == 200) {
            List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);
            JSONArray resultDatas = new JSONArray();

            for (JSONObject result : resultList) {
                ObjectMapper objectMapper = new ObjectMapper();
                String jsonString = result.toJSONString();
                try {
                    JResponse2 response2 = objectMapper.readValue(jsonString, JResponse2.class);
                    Kv2 kv = response2.getGA().getCglPdo().getKvs().getKv();
                    String coilNoOut = kv.getCoil_no_out();
                    if (null != coilNoOut) {
                        resultDatas.add(coilNoOut);
                    }
                } catch (JsonMappingException e) {
                    throw new RuntimeException(e);
                } catch (JsonProcessingException e) {
                    throw new RuntimeException(e);
                }

            }
            JSONObject data = new JSONObject();
            data.put("tableData", resultDatas);
            // 计算总条数 添加
            Integer total = 0;
            data.put("total", total);
            return ResultData.ResultDataSuccess(data, total);
        } else {
            return ResultData.ResultDataFaultGd("failed", "params: " + resultData.get("param"));
        }
    }

    @Override
    public ResultData findAllByMatNo(JSONObject jsonObject, String path) throws JsonProcessingException {
        ObjectMapper om = new ObjectMapper();
        RequestContent rc = om.readValue(jsonObject.toString(), RequestContent.class);
        List<String> coilNoList = rc.getCoil_no_list();
        if (null != coilNoList && coilNoList.size() > 0) {
            JSONArray resultDatas = new JSONArray();
            JSONObject data = new JSONObject();
            for (String s : coilNoList) {
                // 获取数据中心数据
                JSONObject resultData = findAllByMatNoFor(s);
                // 读取数据中心数据
                Integer code = resultData.getInteger("code");
                if (code == 200) {
                    List<JSONObject> resultList = JSONArray.parseArray(JSON.toJSONString(resultData.getJSONArray("results")), JSONObject.class);

                    for (JSONObject result : resultList) {
                        ObjectMapper objectMapper = new ObjectMapper();
                        String jsonString = result.toJSONString();
                        JSONObject json = new JSONObject();

                        JsonResponse response = objectMapper.readValue(jsonString, JsonResponse.class);
                        Kv gaCglpdiKv = response.getGA().getCglPdi().getKvs().getKv();
                        Kv gaCglpdoKv = response.getGA().getCglPdo().getKvs().getKv();
                        Kv gaPredictKv = response.getGA().getPredict().getKvs().getKv();
                        Kv hsmHsmpdoKv = response.getHSM().getHSM_PDO().getKvs().getKv();
                        Kv pltcmMppKv = response.getPLTCM().getMpp().getKvs().getKv();

                        List<Double> sizeProductLenList = hsmHsmpdoKv.getSize_product_len();
                        if (null != sizeProductLenList && sizeProductLenList.size() > 0) {
                            Double sizeProductLen = sizeProductLenList.get(0);
                            json.put("size_product_len", sizeProductLen);//长度
                        } else {
                            json.put("size_product_len", null);//长度
                        }

                        List<String> hotCoilNoList = gaCglpdiKv.getHot_coil_no();
                        if (null != hotCoilNoList && hotCoilNoList.size() > 0) {
                            String hotCoilNo = hotCoilNoList.get(0);
                            json.put("hot_coil_no", hotCoilNo); //热轧卷号
                        } else {
                            json.put("hot_coil_no", null); //热轧卷号
                        }

                        List<String> coilNoOut = gaCglpdoKv.getCoil_no_out();
                        if (null != coilNoOut && coilNoOut.size() > 0) {
                            json.put("coil_no_out", coilNoOut.get(0)); //卷号
                        } else {
                            json.put("coil_no_out", null); //卷号
                        }

                        List<Double> thicknessOut = gaCglpdoKv.getThickness_out();
                        if (null != thicknessOut && thicknessOut.size() > 0) {
                            json.put("thickness_out", thicknessOut.get(0)); //厚度
                        } else {
                            json.put("thickness_out", null); //厚度
                        }

                        List<String> shopSignCode = gaCglpdoKv.getShop_sign_code();
                        if (null != shopSignCode && shopSignCode.size() > 0) {
                            json.put("shop_sign_code", shopSignCode.get(0)); //钢种
                        } else {
                            json.put("shop_sign_code", null); //钢种
                        }

                        List<String> productTime = gaCglpdoKv.getProduct_time();
                        if (null != productTime && productTime.size() > 0) {
                            String s1 = productTime.get(0);
                            json.put("product_time", s1);
                        } else {
                            json.put("product_time", null); //生产结束时间
                        }
                        List<Double> widthOut = gaCglpdoKv.getWidth_out();
                        if (null != widthOut && widthOut.size() > 0) {
                            json.put("width_out", widthOut.get(0)); //宽度
                        } else {
                            json.put("width_out", null); //宽度
                        }

                        List<Double> yieldMaxList = gaPredictKv.getYield_max();
                        List<Double> yieldMinList = gaPredictKv.getYield_min();
                        List<Double> predictPointYsList = gaPredictKv.getPredict_point_ys();
                        List<Double> passRateYsList = gaPredictKv.getPass_rate_ys();
                        if (null != yieldMaxList && yieldMaxList.size() > 0) {
                            Double yieldMax = yieldMaxList.get(0);
                            json.put("yield_max", yieldMax);
                        } else {
                            json.put("yield_max", null);
                        }
                        if (null != yieldMinList && yieldMinList.size() > 0) {
                            Double yieldMin = yieldMinList.get(0);
                            json.put("yield_min", yieldMin);
                        } else {
                            json.put("yield_min", null);
                        }
                        if (null != predictPointYsList && predictPointYsList.size() > 0) {
                            Double predictPointYs = predictPointYsList.get(0);
                            json.put("predict_ys", predictPointYs);
                        } else {
                            json.put("predict_ys", null);
                        }
                        if (null != passRateYsList && passRateYsList.size() > 0) {
                            Double passRateYs = passRateYsList.get(0);
                            json.put("pass_rate_ys", passRateYs);
                        } else {
                            json.put("pass_rate_ys", null);
                        }

                        List<Double> tensionMaxList = gaPredictKv.getTension_max();
                        List<Double> tensionMinList = gaPredictKv.getTension_min();
                        List<Double> predictPointTsList = gaPredictKv.getPredict_point_ts();
                        List<Double> passRateTsList = gaPredictKv.getPass_rate_ts();
                        if (null != tensionMaxList && tensionMaxList.size() > 0) {
                            Double tensionMax = tensionMaxList.get(0);
                            json.put("tension_max", tensionMax);
                        } else {
                            json.put("tension_max", null);
                        }
                        if (null != tensionMinList && tensionMinList.size() > 0) {
                            Double tensionMin = tensionMinList.get(0);
                            json.put("tension_min", tensionMin);
                        } else {
                            json.put("tension_min", null);
                        }
                        if (null != predictPointTsList && predictPointTsList.size() > 0) {
                            Double predictPointTs = predictPointTsList.get(0);
                            json.put("predict_ts", predictPointTs);
                        } else {
                            json.put("predict_ts", null);
                        }
                        if (null != passRateTsList && passRateTsList.size() > 0) {
                            Double passRateTs = passRateTsList.get(0);
                            json.put("pass_rate_ts", passRateTs);
                        } else {
                            json.put("pass_rate_ts", null);
                        }

                        List<Double> elMinList = gaPredictKv.getEl_min();
                        List<Double> elMaxList = gaPredictKv.getEl_max();
                        List<Double> predictPointElList = gaPredictKv.getPredict_point_el();
                        List<Double> passRateElList = gaPredictKv.getPass_rate_el();
                        if (null != elMaxList && elMaxList.size() > 0) {
                            Double elMax = elMaxList.get(0);
                            json.put("el_max", elMax);
                        } else {
                            json.put("el_max", null);
                        }
                        if (null != elMinList && elMinList.size() > 0) {
                            Double elMin = elMinList.get(0);
                            json.put("el_min", elMin);
                        } else {
                            json.put("el_min", null);
                        }
                        if (null != predictPointElList && predictPointElList.size() > 0) {
                            Double predictPointEl = predictPointElList.get(0);
                            json.put("predict_el", predictPointEl);
                        } else {
                            json.put("predict_el", null);
                        }
                        if (null != passRateElList && passRateElList.size() > 0) {
                            Double passRateEl = passRateElList.get(0);
                            json.put("pass_rate_el", passRateEl);
                        } else {
                            json.put("pass_rate_el", null);
                        }

                        List<Double> rMinList = gaPredictKv.getR_min();
                        List<Double> rMaxList = gaPredictKv.getR_max();
                        List<Double> passRateRList = gaPredictKv.getPass_rate_r();
                        List<Double> predictPointRList = gaPredictKv.getPredict_point_r();
                        if (null != rMaxList && rMaxList.size() > 0) {
                            Double rMax = rMaxList.get(0);
                            json.put("r_max", rMax);
                        } else {
                            json.put("r_max", null);
                        }
                        if (null != rMinList && rMinList.size() > 0) {
                            Double rMin = rMinList.get(0);
                            json.put("r_min", rMin);
                        } else {
                            json.put("r_min", null);
                        }
                        if (null != predictPointRList && predictPointRList.size() > 0) {
                            Double predictPointR = predictPointRList.get(0);
                            json.put("predict_r", predictPointR);
                        } else {
                            json.put("predict_r", null);
                        }
                        if (null != passRateRList && passRateRList.size() > 0) {
                            Double passRateR = passRateRList.get(0);
                            json.put("pass_rate_r", passRateR);
                        } else {
                            json.put("pass_rate_r", null);
                        }

                        List<Double> predictPointNList = gaPredictKv.getPredict_point_n();
                        List<Double> nMinList = gaPredictKv.getN_min();
                        List<Double> nMaxList = gaPredictKv.getN_max();
                        List<Double> passRateNList = gaPredictKv.getPass_rate_n();
                        if (null != nMaxList && nMaxList.size() > 0) {
                            Double nMax = nMaxList.get(0);
                            json.put("n_max", nMax);
                        } else {
                            json.put("n_max", null);
                        }

                        if (null != nMinList && nMinList.size() > 0) {
                            Double nMin = nMinList.get(0);
                            json.put("n_min", nMin);
                        } else {
                            json.put("n_min", null);
                        }

                        if (null != predictPointNList && predictPointNList.size() > 0) {
                            Double predictPointN = predictPointNList.get(0);
                            json.put("predict_n", predictPointN);
                        } else {
                            json.put("predict_n", null);
                        }
                        if (null != passRateNList && passRateNList.size() > 0) {
                            Double passRateN = passRateNList.get(0);
                            json.put("pass_rate_n", passRateN);
                        } else {
                            json.put("pass_rate_n", null);
                        }

                        List<Double> realYs1List = pltcmMppKv.getReal_ys1();
                        List<Double> realTs1List = pltcmMppKv.getReal_ts1();
                        List<Double> realEl1List = pltcmMppKv.getReal_el1();
                        List<Double> realR1List = pltcmMppKv.getReal_r1();
                        List<Double> realN1List = pltcmMppKv.getReal_n1();
                        if (null != realYs1List && realYs1List.size() > 0) {
                            Double realYs1 = realYs1List.get(0);
                            json.put("real_ys1", realYs1);
                        } else {
                            json.put("real_ys1", null);
                        }
                        if (null != realTs1List && realTs1List.size() > 0) {
                            Double realTs1 = realTs1List.get(0);
                            json.put("real_ts1", realTs1);
                        } else {
                            json.put("real_ts1", null);
                        }
                        if (null != realEl1List && realEl1List.size() > 0) {
                            Double realEl1 = realEl1List.get(0);
                            json.put("real_el1", realEl1);
                        } else {
                            json.put("real_el1", null);
                        }
                        if (null != realR1List && realR1List.size() > 0) {
                            Double realR1 = realR1List.get(0);
                            json.put("real_r1", realR1);
                        } else {
                            json.put("real_r1", null);
                        }
                        if (null != realN1List && realN1List.size() > 0) {
                            Double realN1 = realN1List.get(0);
                            json.put("real_n1", realN1);
                        } else {
                            json.put("real_n1", null);
                        }

                        List<String> coilId1 = pltcmMppKv.getCoil_id1();
                        if (null != coilId1 && coilId1.size() > 0) {
                            json.put("coilId1", coilId1.get(0));
                        } else {
                            json.put("coilId1", null);
                        }
                        resultDatas.add(json);
                    }

                    data.put("tableData", resultDatas);
                }

            }
            return ResultData.ResultDataSuccess(data);


        } else {
            return ResultData.ResultDataFaultGd("failed", "params: ");

        }

    }

}